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?
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.
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.
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.
Hello fellow UE user. If you took the time and read the whole discussion you would see that the theory AND the solution are both posted in it, hence it’s marked as solved. I indeed didn’t make a step by step solution like I promised because my work applies to my brain only and could appear as confusing to others as it has other things involved in the code. So, you could just READ and UNDERSTAND and use the solution for your own projects instead of waiting for me to spoon feed you a clean project with a tutorial. I did exactly that and I can now do whatever I want with actors and spawning them. Cheers!