Inventory in Storage Menu could not be detected if the Storage Menu has not been open

Justus

Member
I add an inventory amount item view to the item description. it will display the amount in Bag(inventory id = 1),and the amount in StorageBox(inventory id =2)
- the Bag inventory is a component in the character
- the StorageBox inventory is a componet of Storage Menu

How could I prevent this warning message, or how to make sure inventorys are all initialized, neglecting whether related menu is open or not.
1652781455319.png
 
You have two choices,
Either ensure that the storage Inventory gameobject was enabled at least for one frame, the time to call Awake.
Or Manually call Awake on the InventoryIdentifier and Inventory component (they are both public)
 
why not add an option to Inventory like "Awake when game init" as an enhancement? I feel this is a common requirement when you have several different storage boxes.
 
Well Unity doesn't allow that. An object must be enabled at least once for it to be initialized with Awake.
So instead of putting it inside the menu you can keep it outside if you want. Or you can leave the Menu enabled in edit mode and let the panel close on start.

Initializing objects that are disabled can only be done through code from other scripts. We do it for panels using the panel manager for example. But the only reason we can do it is because all panels are children on the panel user.
Inventories can be anywhere in the scene so it does not make sense to have such feature
 
Top