Hello, I’ve been stuck on this problem for a couple of days and maybe you can help me out…
I’ve forked my private project into a public project and stripped everything that wasn’t needed to replicate the bug.
You can find the project here: https://playcanvas.com/project/705604
The problem is within my Inventory system.
To reproduce the bug follow the following steps starting from the InitialScene:
- click on “play”
- click on the red square (that will fill the inventory)
- click on the arrow pointing to east (that will change scene)
- click on the arrow pointing to west (that will take you back to the previous scene)
- click on the inventory button (that will open the inventory, of course)
The error is:
Uncaught TypeError (Cannot read property ‘enabled’ of null)
at ElementComponent.get (playcanvas-stable.dbg.js:28112), it seems to be related to the update of the hierarchy when the parent panel entity is enabled
the issue happens when there are items in the inventory, so it must be some element component of the items icons that is expected to have the enabled property, I guess…
If you open the inventory before you return to that scene, it doesn’t happen.
Technically this is what I’m trying to do:
The Inventory is a script added to an Entity which in turn is a child of a Screen Entity that embeds the UI.
Most of the entities in the initialScene are meant to be carried around for the whole game, so I’ve renamed the root entity to PersistenRoot. When I change scene the first time (pushing the “play” button) only part of the entities are destroyed.
From that point on, changing scene (clicking on the yellow arrows) will destroy the Root entity of the actual scene (always mantaining the PersistentRoot).
Each scene has an entity with a SceneManager script (that works as a singleton registering itself when the scene is loaded, overwriting the previous SceneManager instance).
Items will be scattered through the games, each scene will contain the items that can be found there as child of the SceneItems entity.
Each item has an ItemIcon script that on initialize will check if the Inventory contains a copy of that item (using a string key). If the inventory contains the key, the ItemIcon will self destruct (the name of the entity destroyed is printed on the console, to keep track of this).
Otherwise it will register itself to the SceneManager’s item icons list (so it can be easily found by other scripts).
When the player obtains an item, that item’s key is searched in the Inventory (if it’s found there, only the quantity held by the player is changed), or in the SceneManager (in this case, the ItemIcon is reparented to the Inventory layout entity and added in the Inventory list).
When it’s reparented, its name is changed by appending “(in inventory)” to it.
Whenever the Inventory is opened, all children of the layout are printed in the console, so I know that they (and their element component) are not null.
Do you have any tips on how to tackle this problem?