Forum rules - please read before posting.

Custom action loses assigned game object after scene change

Hi,
I have a custom action to enable/disable a gameobject depending on the menu you're currently on.

E.g. So lets say you're on the pocket menu, when you open it then it runs the custom action and disables the Apple gameobject, but when you go back to the main menu it turns it back on.

It works, but the problem is as soon as you change scenes it seems to lose the variable of the object I assigned. It has the constant ID in the action as well..

MissingReferenceException: The variable m_Object of ActionDisableObject doesn't exist anymore.
You probably need to reassign the m_Object variable of the 'ActionDisableObject' script in the inspector.

I've been messing around with it for 2 days and I can't figure it out so I'm back here again lol. Does anyone know why?

Here's the link to the action code: https://pastebin.com/nHLZRHYK

Thank you :)

Comments

  • Just as a note the object is in every scene with the same constant ID

  • What is the error message in full (stacktrace included), and are you using this Action inside an asset file or a scene-based ActionList such as a Cutscene?

    This may be a red herring, but make sure your types are consistent:

    m_Object = (GameObject)EditorGUILayout.ObjectField("Object to Disable", m_Object, typeof(GameObject), true);
    

    If the object is in every scene, an alternative approach would be to make it a prefab and spawn it in when the game begins, marking it as DontDestroyOnLoad so that it survives scene changes.

    Generally, however, it's best not to disable GameObjects that require a Constant ID reference. AC can only "see" such objects that are enabled - so if it's disabled then AC may not be able to re-enable it. Using either the Object: Teleport Action or Object: Set visibility Actions are typically safer ways of temporarily hiding such objects.

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.