Ok, I think I understand. At some point you might need a more complete saving/serialization implementation, but here’s a quick and simple solution that I tested. I uploaded the sample code [here][1] for reference.
Going back to the main issue, the problem is that we cannot save a list of actor references as these will be invalidated when the level is unloaded and will no longer point to anything. If we had a value such as a string or integer that uniquely identifies an actor then we can save it in our GameInstance and it won’t be invalidated. It turns out that [UKismetSystemLibrary::GetObjectName][2] can give us that (see [here][3] for more info), so let’s use ObjectName as a way to uniquely identify an actor.
Going with the example of saving a list of doors that have been opened, we’ll create a variable in our GameInstance called UnlockedDoorNames
which is a string array of the names of opened doors.
Then in our door blueprint we let each door add itself to this array when it’s unlocked by the player, similar to what you’re doing in your code:
So now we have a unique reference to all the open doors which will persist after a level load/unload, but it’s not a reference to the actor itself, and we can’t do much with it. To find the actual actor using its ObjectName we would need to iterate through all actors in the level comparing their ObjectName until we get a match, which is too expensive. So instead let’s do a few things:
1- Create a tag which we will use in the editor to mark every actor that needs to be referenceable across different levels. Let’s call this tag Referenceable
and tag our BP_Door with it. Using a tag makes it easy to batch edit multiple actors and tag them at once (using the property matrix editor).
2- Create a new variable in GameInstance called ActorReferences
, which is a map of type String (ObjectName) → Actor Reference

3- Create a helper function on GameInstance called PopulateActorReferences
. This looks for all actors with the Referencable tag in the current world and adds an entry in the ActorReferences
map linking the ObjectName with a reference to the actor.
Now we just need to call this function once at BeginPlay and we have a reference to every Referenceable actor through its ObjectName, which means using our UnlockedDoorNames
array we can actually retrieve the list of opened door actors like so:
Now we finally have a reference to each door actor and we can do anything we want with it.
Hope this helps. The sample code looks a bit different as it’s more robust but the idea is the same.