Where should inventory items go when in your inventory so they exist after a level change?

My inventory keeps up with an array of actor references and sets visibility and collision off for the actor when in inventory. The problem is when the character switches levels the objects that the references refer to are destroyed. You can keep the references in a GameInstance object and the reference values are still there but the data they point to is gone.
How should I handle inventory items for a multi-level project?

I believe what you want to use is the game mode blueprint.
https://docs.unrealengine.com/latest/INT/Gameplay/HowTo/SettingUpAGameMode/Blueprints/index.html

Alternatively you can save it in a save file, so it stores information in a separate file that will only get overwritten when you tell the project to do so.

Cheers!

Thanks for the links. I read through the GameMode info, but I didn’t find an answer. The issue is the actors in a level existing after switching levels not keeping track of data.

I guess I’m going to have to respawn actors after opening a new level. This means keeping track of class and properties for each item. This seems like doing it the hard way, but it should work. Any further suggestions are welcome.

You need to use Game Instance BP as it lives on no matter how many times you change the level.

After that you need to save it if you want it to persist after closing the game.

Mr Maranbe0 has the savagame link already. :slight_smile:

Thanks for the input. The GameInstance works for persistent data.

I got the inventory to work with the level transition. I did it by recording inventory data (class and properties) before level change and then spawning actors after level change using the recorded data. It’s not pretty but it works!

i haven’t done this myself and i’m not 100% sure it’s right for you, but there seems to be something called seamless-travel which uses a “transistion map” to which you can “save” some actors for the next level.

here’s some documentation: Travelling in Multiplayer | Unreal Engine Documentation

it says it’s for multiplayer. not sure if it would work for singleplayer.


i believe (again, haven’t actually done this either…) you can also use level streaming and keep some of the actors.