Get all static meshes in level into array

Hello UE4 Community!

I a have a project where the player can destroy puzzle elements, but this can lead to the puzzle became unsolvable. So the player needs to have the ability to reset to the nearest checkpoint and respawn all the puzzle pieces.
I came up with an idea where I want to find all the movable static meshes with the tag “puzzle” and get their coordinates and their static mesh shapes into an array. I want to this in the level blueprint when Event Begin Play. So when you reset yourself it calls a function or custom event (in the character blueprint) to destroy all static meshes referenced in the array and respawn them exactly where they were.
The problem is that I’m a Java programmer and I’m new to blueprints and I’m not really sure if this is possible and if it is then how to do it.
Oh and reloading a level isn’t a solution because I want the music to keep playing.

Thanks in advance!

You can use the BP node named ‘Get all actors of class’ and select static mesh in the drop down and then store them into an array. That might do the job for you.
Hope this is helpful.

The GetAllActroOfClass can work unless you do it more than once. It is not overly efficient.

As an alternative, you can keep an array in your GameState of all the actors of a certain type. Then
when the actors are created, in their BeginPlay you have them add them selves to the array.
In EndPlay you have them remove them selves. This second approach is more useful if you need an ongoing list of a cretain type of actor. (E.g. in The Dead Linger NPC LOD Proxies are tracked this way)

Thanks! I’ll check this out as soon as I can. :slight_smile:

Thanks! I thought there is a way to reference to the actual level in other blueprints. This works just fine tho I’m curious if is this possible.