Forum rules - please read before posting.

MissingReferenceException spam when changing scene (AC_Trigger / StateHandler)

edited February 26 in Technical Q&A

Hi,

I encountered a recurring issue when switching from one specific scene (my “Museum” scene) back to the main menu.
(with chatgpt help)
Setup

AC version: 1.85.4
Unity version: 6000.3.1f1

Transition:

Scene → Change scene → Menu
Also tested with Engine → End Game → Restart Game
Happens only when going Museum → Menu
Does NOT happen when going 1896 scene → Menu

Symptoms
When changing scene from Museum to Menu, the Console starts spamming:

MissingReferenceException: The object of type 'AC.AC_Trigger' has been destroyed but you are still trying to access it.
AC.AC_Trigger._Update()
AC.StateHandler.Update()
image spam

This error repeats every frame.
Additionally:
The menu becomes non-interactive after the transition.
Disabling all AC_Trigger components before scene change did NOT fix it.
Removing “Remember Trigger” components from triggers (100+ tested) did NOT fix it.

Investigation
The issue appears to be caused by StateHandler keeping a reference to a destroyed AC_Trigger in its internal Triggers list.
In StateHandler.Update() (around line ~264 in my case), the code was:

if (!triggerIsOff)
{
    for (int i = 0; i < Triggers.Count; i++)
    {
        Triggers[i]._Update();
    }
}

When one of the triggers had already been destroyed during the scene transition, its reference remained in the Triggers list, causing _Update() to be called on a destroyed object → MissingReferenceException every frame.

Temporary Fix Applied (with chatgpt help)

Adding a null cleanup before updating the triggers resolved the issue completely:

if (!triggerIsOff)
{
    Triggers.RemoveAll(t => t == null);

    for (int i = 0; i < Triggers.Count; i++)
    {
        Triggers[i]._Update();
    }
}

After this change:
No more console spam
Menu works normally
Scene transitions behave correctly

Question

Is this expected behavior, or should StateHandler automatically purge destroyed trigger references during scene unload?

It seems that under certain scene configurations (in my case, only the Museum scene), a destroyed AC_Trigger can remain referenced in the Triggers list.

Thanks in advance.

Comments

  • Try the latest release, v1.85.5 - it addresses an issue related to Triggers when existing scenes.

  • After updating to the latest version of Adventure Creator, the issue is completely resolved.
    Thanks for the continued support and improvements!

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.