I can save actors in Array but can't Spawn them.

I can add my actors to an Array for saving game, I checked it with print strings on both adding and loading. However, what I want to do is check if an actor is in the level, and if not spawn it. I tried with actor references and the best thing I got was being able to spawn the actor from the Array ONLY if it was already in the level, so I got double actors.

I also checked that the variables also save within the array so I have a Transform variable that stores the actor’s position on Play. How can I load actors back in the level at the exact Transform they had while saved?

1 Like

For each actor, you need to store the type of actor, and it’s transform.

When I say ‘type’, I mean a type devised by you, so you know what’s going on. It could be the class, but that really depends on the setup you have.

I’m guessing that most of them are either actor or blueprint? So you just need ‘actor’ or the class of the BP, and it’s transform.

When the level starts, load the save game, and check everything is at the correct transform. If not, move it. If nothing is stored, remove the actor.

Gimme a bit more info on the types of things you have in the level…

Hello! I want to do this for everything that is an actor. Depending on how the player has advanced in the game, there may be various blueprints present or missing. Inventory items, scenery, anything. So I tried with Actor type in my arrays. Print string says they are there when saving and loading, but unless they are already in the level, they don’t spawn. I save the transform of each actor inside its blueprint when the game starts and it seems to work. NOTE: In this photo I tried with a blueprint I use for Inventory Items called BasicItem. But same happens with Actor.

I had trouble with this too. Here is my solution, but I don’t know if this is proper or efficient.

First, instead of saving an array of objects, I made a structure, then saved the Transform, Actor Class, and Object like this:

Then spawn them like this:

It seems like all you would need is the transform and the class, but for some reason I had to save the object as well. Hope this helps

You need to learn the difference between objects references and classes. When you spawn an actor into the level you can only spawn it from a class not an object.

For example, if you spawn in an actor and then store it as an object reference (which is what your objects in dreamland array looks like it is), that array is storing the object in the level. Once you destroy that object, the reference to it in the array will become null because it no longer exists but the array can still figure out what class it came from.

So when you cast to Basic item you should be getting a failed cast which means the Transform you are trying to pull from the cast node is going to be empty or zero.

Here is a test you should do. Connect the ‘cast failed’ pin to a print node and see if it logs. You should also check your level world outliner because the actors a likely still spawning, just at location 0 0 0, scale 0 0 0 and rotation 0 0 0. Because the scale is 0 you wont see them but they will still show in the world outliner.

Instead of saving an object reference you should save a struct that stores the class and transform and any other data you need to reproduce.

Can I see your code that loads the save game and spawns the actors after loading the level?

For people coming to see the solution to this, read GrimStarGames’s answer to get the theory and do what is in ugmoe’s photos.

Ugmoe is right. I was trying to load references, that’s why I could only spawn actors only if they were in the level already, and that’s why the array had the actors in it even on loading. You both helped me a lot. I suspected I should do something towards structures, I will figure it out and post the solution for people having this problem in the future.