1
\$\begingroup\$

I want to make a game where I can hold tools in my hand and inventory. Obviously I want to pass them between levels and maybe even game sessions. Question is, how would I do that?

With simple variables like amount of money or HP, all I do is store a variable in the Game Instance. But what about, for example, a tool that has more data, like the class type, durability, maybe value? Even worse, whole array of them?

The way I use that in game is, there's an actor representing the tool. But even if I store array of those in the game instance, the actors get destroyed while changing level and the array just points empty memory. I could just spawn new ones by using the class type - but that is not enough for me.

My idea is to create something... maybe a struct, that would hold the information and then recreate the inventory item actors according to the data in the struct.

My questions: What are other ways to do it? and Is there something fundamentally wrong with the way I'm storing the items in my inventory now?

\$\endgroup\$

2 Answers 2

2
\$\begingroup\$

What I did is to create a Struct for each object to be saved and then recreate it at begin play from what's loaded in the game instance.

Every object that has to be saved tells the game instance his last state in this way:

single saving

and whenever you save, the game instance provide saving those parameters:

saving

Whenever begin play start every object retrieve his starting info from game instance (properly updated with last saved status) and rebuild himself.

loading


In that way it works very well, we use level streaming and this logic seems to be solid, our Save Game entity has arrays to collect every object considering only what's important to save the state.

\$\endgroup\$
0
\$\begingroup\$

You can store an actor in the gameinstance as well. You can add your actors to toot AddToRoot() so they will not be destroyed.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .