How do I get the location for each instance of a single actor within my level?

Hello!
Right now I am working on making a “reset” button for my puzzle game so the player can reset the puzzle if needed. I have a box item that I have several of in my level and I want to get the location of each one and store it so that when I reset the puzzle they go back to their original places.

As of right now I have this on the box item to get its location and save it


and I have this in my gamemode for when I reset the puzzle

The code I have now is causing the boxes to move from their original location on play and start falling from the sky for some reason. I’m not sure how I would go about getting the locations of each individual box or how to store it. I assume I should use an array but I’m relatively new to using blueprints and am not sure how to properly set one up.

Do I understand correctly that you don’t really want to reset? You want to restore a save game so you can continue playing?

If so, then the issue I’m seeing is that you only have one box position in your SaveGame. You’ll need an array of vectors. If all your boxes are identical, then you’ll need to just spawn a box for each position. If the boxes are pre-existing, then you’ll just do a GetAllActorsOfClass, iterate over it with For Each node and then set the positions.

If I’m not mistaken, I think the teloport checkbox should be checked for setting positions.

As for falling, dunno. Maybe turn gravity off or check your collision settings.

edit: Also, it’s possible the boxes are falling because you’re moving them all to the same place and they’re colliding with each other so they have to go somewhere so they fall down. So it’s possible this resolves itself once you set each box to a different position.

It’s not resetting, because you just check the SG exists, but don’t read it :slight_smile:

I realized this right after posting lol. I ended up finally finding a video where someone was trying to do something similar and got something working.
Made a struct to store the class and location of each object and then put this code in my player controller to actually save the data


The only downside to this is that when I load the data it doesn’t actually reset their locations, it just respawns them so I have to destroy them before I load the save

Right, so you can try changing that spawn node to a ‘set actor transform’ node?

Something like that.

Trying to find a tutorial that does exactly what you want is hardly ever an easy job. You already know enough to get this done, I think;

Begin play
Save positions
Let player move objects
Read positions
Reset object positions

Didn’t even notice I was using a spawn actor node. Been looking at this project too long lol. Thank you for pointing it out :slight_smile:

1 Like

Ok so you mean actors dragged in that execute when the level executes VS actors SPAWNED in. If its dragged in actors you could get each reference from the level blueprint. Else when you spawn them I suppose you could set an OBJ variable inside perhaps the current game mode and store it there.