Forum rules - please read before posting.

Getting nullref when trying to open menu

Heyo, I upgraded to 1.47 recently, and I'm having a problem with my Menus.

I have one on-screen button, which, when pressed, opens a second Menu and fills the label on it with a specific text when opening, like this:



public static void OnMenuEnable (AC.Menu _menu)
{
if (_menu.title == "Dossier") {
//these declarations are usually in void Start() but I put them here for readability, that's why I'm not using _menu:
MenuLabel notestitle = PlayerMenus.GetElementWithName ("Dossier", "Title") as MenuLabel;
MenuLabel notes = PlayerMenus.GetElementWithName ("Dossier", "Notes") as MenuLabel;
//clears the label with a default message when opening the Menu
notestitle.label = string.Empty;
notes.label = "Select a topic from the list to learn more.";
}
}


But since 1.47 I get a nullref that it can't find the label, and so the second Menu never opens.

There is also a toggle in the options Menu that I try to set in a similar way on gamestart, and that too gives a nullref. It's almost like using anything PlayerMenus related in a script doesn't work.

Crazy thing is: this happens everywhere, including in newly-created scenes, EXCEPT the main menu scene and the Intro scene, and for the life of me I can't figure out why. There's nothing in the starting cutscenes of those scenes that does anything that the other scenes don't as far as I can tell. But it has to be in there I guess. I'm stumped.

All my Menus are AC ones, no UnityUIs.

Comments

  • Please post the full error message that you get - knowing that it's a nullref isn't enough, I'll need to see the whole thing.
  • Gotcha, the error at the start is:

    NullReferenceException: Object reference not set to an instance of an object
    GlobalScript.Start () (at Assets/Scripts/GlobalScript.cs:34)

    Which refers to:

    void Start() {
    33 continueToggle = PlayerMenus.GetElementWithName("Options", "ContinueToggle") as MenuToggle;
    34 continueToggle.isOn = true;

    And when trying to open the Menu it's this one:

    NullReferenceException: Object reference not set to an instance of an object
    Dossier.ShowNote (Int32 clicked) (at Assets/Scripts/Dossier.cs:112)
    AC.MenuSystem.OnMenuEnable (AC.Menu _menu) (at Assets/AdventureCreator/Scripts/Menu/MenuSystem.cs:42)
    AC.Menu.TurnOn (Boolean doFade) (at Assets/AdventureCreator/Scripts/Menu/Menu classes/Menu.cs:1304)
    AC.PlayerMenus.CheckCrossfade (AC.Menu _menu) (at Assets/AdventureCreator/Scripts/Controls/PlayerMenus.cs:1310)
    AC.Menu.EndTransitionOff () (at Assets/AdventureCreator/Scripts/Menu/Menu classes/Menu.cs:1196)
    AC.Menu.HandleTransition () (at Assets/AdventureCreator/Scripts/Menu/Menu classes/Menu.cs:1506)
    AC.PlayerMenus.UpdateMenu (AC.Menu menu) (at Assets/AdventureCreator/Scripts/Controls/PlayerMenus.cs:627)
    AC.PlayerMenus.UpdateAllMenus () (at Assets/AdventureCreator/Scripts/Controls/PlayerMenus.cs:1257)
    AC.StateHandler.Update () (at Assets/AdventureCreator/Scripts/Game engine/StateHandler.cs:207)

    which refers to:

    112 notestitle.label = string.Empty;
  • This is because the Start() function in your script is being called before the Start() function in PlayerMenus.cs is called.  The latter is the function that generates the Menus, so they don't yet exist at the time you reference them.

    You can work around this by amending their relative execution orders by clicking on both scripts in the Project window and amending their Script Execution Order so that your own script runs after PlayerMenus.
  • Ahhh interestinggg, you are right, that solved it!

    Man, haven't thought about script execution order since AGS... thanks a bunch! I wóuld never have found this out on my own.
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.