Inventory on persistent singleton

Bernkastel

Member
Is it possible to have the player's main inventory be a separate persistent singleton in the current build of Inventory System? I find it hard to do things like add items to the inventory in between scenes. It would be a lot simpler to have a reference to it that is persistent. Also what about scenes that do not contain the player prefab where the player inventory is placed?

You said previously that there are public inventory setters for dynamic panel owner and Inventory Interactor. Is it possible for this to be considered in future updates?
 
Depending on how you organize your game it is possible.

The Inventory is a component you can set wherever you want. But in some cases we assume the Inventory is on the Player game object to find other components like the ItemUser, Unity Input, Inventory Interactor, etc...

The way I keep the inventory between scenes in the Adventure Kit is by keeping the character between scenes.
I actually have a scene with all the required component/managers including the character and then load/unload the environment scenes additively.

How would you plan to keep your Inventory persistant? Would you like to have it separate from the player gameobject? I wonder if you move the Inventory component between the character and another gameobject, I doubt that would work very well though.

There is also the choice to have two seperate Inventories, and sync them when loading/unloading scenes
 
Anyone using the Topdown/Corgi Engines will have the same issue as me, as the player is instantiated on level load by design. So in between scenes and in scenes where the player isn't, the inventory won't be there. I think removing the assumption of where the inventory is if possible would allow more room to leverage the inventory system. I was planning on having an inventories that would most likely stay around on a persistent singleton manager that handles all sales made and tallies them up at the end of the day in game.

I thought about syncing the inventories, on scene change adding the synced inventory to a persistent one, but then It feels like replacing the inventory on the player would lead to unnecessary issues.

There are seemingly a few answers, but its hard to say which will cause the least headaches with incompatibility with future updates.
 
There is also the choice of saving/loading save data to the inventory. Such that whenever you load and unload the player you can save and then if you need to, you may load that save data to another inventory within your managers.

I will look into allowing the Inventory to stay on a persistent object which is not the player character. The main possible struggle will be the events, since a lot of events are triggered on a target component which is usually the object with the Inventory, ItemUser or Unity Input components.

I would recommend you give it a try yourself and let me know the exact issues with your use case, and then perhaps I can make a few properties and functions public which would solve it.
 
Top