Forum rules - please read before posting.

KickStarter.player.portraitIcon.Reset (); gives error in both v1.71.0 and 1.71.1

edited May 9 in Technical Q&A

Hi, I just found this script KickStarter.player.portraitIcon.Reset (); gives the following error message in both v1.71.0 & 1.71.1. Is the API changed or would that be a bug? I am using the script in a MonoBehaviour script that is attached to the Inventory Menu UI.

NullReferenceException: Object reference not set to an instance of an object
InventoryScript.OnEnable () (at Assets/Ricky/Scripts/UI/Inventory/InventoryScript.cs:98)
UnityEngine.Object:Instantiate(Canvas)
AC.Menu:LocateLocalCanvas() (at Assets/Plugins/AdventureCreator/Scripts/Menu/Menu classes/Menu.cs:3022)
AC.Menu:LoadUnityUI() (at Assets/Plugins/AdventureCreator/Scripts/Menu/Menu classes/Menu.cs:372)
AC.PlayerMenus:RebuildMenus(MenuManager) (at Assets/Plugins/AdventureCreator/Scripts/Controls/PlayerMenus.cs:149)
AC.PlayerMenus:OnInitPersistentEngine() (at Assets/Plugins/AdventureCreator/Scripts/Controls/PlayerMenus.cs:87)
AC.StateHandler:Initialise(Boolean) (at Assets/Plugins/AdventureCreator/Scripts/Game engine/StateHandler.cs:99)
AC.KickStarter:SetPersistentEngine() (at Assets/Plugins/AdventureCreator/Scripts/Game engine/KickStarter.cs:157)
AC.KickStarter:Initialise() (at Assets/Plugins/AdventureCreator/Scripts/Game engine/KickStarter.cs:1096)
AC.MultiSceneChecker:Awake() (at Assets/Plugins/AdventureCreator/Scripts/Game engine/MultiSceneChecker.cs:44)

Comments

  • Menus are spawned in before the Player, so it's "KickStarter.player" that is null if you're calling this in OnEnable.

    Try moving this call to the Start function, or wrapping a null-check around it, i.e.:

    if (KickStarter.player != null)
    {
        KickStarter.player.portraitIcon.Reset ();
    }
    
  • Thanks! It's fixed!

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.
Do NOT follow this link or you will be banned from the site!