Inventory Interactor on Object without Inventory

Bernkastel

Member
I would like to have a DoNotDestroyOnLoad main Inventory for the player, however my player prefab is instantiated at runtime at the beginning of every level. I made a separate game object to hold all the player's inventory/currency data and made it do not destroy, however it seems that InventoryInteractor.cs requires the Inventory to be on the same game object. Is there an intended way for me to have a persistent inventory with a non persistent playable character? I wanted to assign the Inventory at runtime to the player prefab but it is protected which I assume is by design and required.

I am also making my Inventory Canvas persistent which is partly why I want to keep the inventory itself persistent. My player prefab had a dynamic panel owner and inventory identifier. On initial load for the first player prefab it sets itself as the owner and works as intended. After switching scenes and re-instantiating the prefab it does not re-assign itself as the owner of the panel. The inventory on the player saved and maintained its item collections, however they were not displayed in the UI after scene transition.
 
I see what the problem is... I was able to reproduce the it fairly easily.

Note that the Dynamic Panel Owner is a feature we recently added in the latest version so I may have overlooked some use cases.

By design the Inventory Interactor and the Item User are supposed to be on the same gameobject as the Inventory. But perhaps I could change that.

I added a public setter to the Inventory Interactor component.
Code:
public Inventory Inventory
{
    get => m_Inventory;
    set => m_Inventory = value;
}

You'll need to set the ItemUser to the Inventory, there's already a public setter for that.

You'll need to set the ItemUser on the InventoryIdentifier too, there's also a public setter for that.

The InventoryInput component needs to be on the same gameobject as the Inventory, that's required. Until we refactor the input system there's no way around it.

That should allow you to split the Inventory from the player game object. Note that you might run into other issues with that set up. If you do let me know and I'll see what I can do.

In the mean time I'll see if I can find a solution for reusing the UI when changing the panel owner... it's slightly complicated since the input, inventory and other things are bound during the initialization of the UI components. I will need to decouple the initialization from the panel owner bindings and perhaps I can make it work.

I'll try to solve this before the next update, but I cannot garantee I'll have time to do so, there are a lot of other tasks I need to cover.

I'm sorry for the inconvenience
 
Thanks for the response, it sounds like a a dynamic inventory owner component is basically required, similar to the dynamic panel owner. As for the Panel Owner issue it sounds like the dynamic owner is meant to bind an owner a single time, and even if I set the owner to null right before setting my new player object as the owner in the next scene it won't work? If this is the case then having a single Starter Scene approach is off the table for the UI until the update.


In the meantime is the safe way for testing and building out the rest of the system to have everything located on the player & the naïve approach with the UI setup?
 
The set ups that work currently is either make both the player and the UI persistent between scenes OR make neither persistent.

There's also the choice of making the player persistent but not the UI... but that does not suit your needs.

The only setup that is missing is the one that would make the most sense for you, having the UI persistent but not the player. I'll look into a solution for that, hopefully it makes it in time before the next update
 
Top