Save actors in the game instance

Hello,
How can I save the actors in the game instance?

This doesn’t work:

Thank you in advance!

Save in what way? Nowhere above are you saving anything.

I want to store actors in the game instance

What do you mean by store? Are you opening a new level?

You add them to an array and that’s it. If you open a new level, the actors get destroyed and the array of references contains useless pointers to now non-existing actors.

The Game Instance persists - other actors do not.

I want to load actors into the game instance, when I go to the other level and back again, the actors don’t have to be there anymore

I want to load actors into the game instance

No such thing exists - that’s not how the engine works. I wish it did! You never move actors in a physical sense. Actors sit in the memory - the references are the addresses.

imagine you have a house with the address. Like we all do. If you blow up the house, you still have the address - you can go there but the house is gone.

When you reload level, the respawned houses are put in another place of the computer memory and new address needs to be made. The old address is useless - something else may occupy that part of memory. Simplifying a wee bit but that’s how it generally works. Memory allocation is dynamic and thank the gaming gods we do not need to worry about it that much…


We talked about this in the other thread. You cannot save actors. You can save their data. The answer to your questions is still the same:

1 Like

I know
I want to store the name of the actor in the GameInstance and when changing level, I want to load the name from the gameinstance and destroy it

Now, that makes much more sense! And that’s precisely what I had linked - the answer is still the same.

I can’t do it somehow.

1 Like

I’ll try to produce an example, in a couple of hours or so.

That would be great!

  • there’s a bunch of uniquely tagged actors in the level:

  • the Game Instance has an empty Name Set container:

  • just before an actor is destroyed, we add their tag to the Game Instance’s set:

  • when the level is loaded, we query that set:

  • we get all actors in the level, look at their tag and attempt to find it in the Game Instance’s set
  • if the tag is present in the set, we Destroy that actor

The above can be optimised further but that’s the gist.

1 Like

Thanks again for your detailed answer and example.
I will try it now.

And if you were to quit & restart the game tomorrow, all you need to do is to save the Game Instance’s set to a Save Game object. When the game is booted again, load a save game and assign the set to the Game Instance.

Hope you can adapt it to your cubes!

1 Like

Your example definitely helped me a lot

Can you also do this without tags, e.g. you search for all actors with the ID name in a map?

Yes. But you’d need to cast.

ok