In Level Blueprint, how to create references to Actors spawned at runtime?

I have a GameMode that spawns different (1-4) controllable characters at runtime. I would like to use the Level Blueprint to switch pawn possession using hotkeys (1-4 for example) like in this tutorial.

How can I instruct it to search for characters, add them to a list/array of references, and then enable the hotkey swap like in the tutorial?

Thanks in advance.

Save their references inside GameMode after spawning, then call GetGameMode inside Level BP, cast to your type and you can get the references.

Hi Phoboz, thanks for answering. I’m trying to do as you said but I’m not quite succeding. How do you save a reference properly? I’m using ‘promote to variable’, but when I get this variable from outside the gamemode it gives error (invalid target).

Can you show your blueprint where you save and get the reference?

If you use BeginPlay to both, spawn and get the reference, it’s possible that getting script is executed first, before the Actor is spawned. In that case you can look into BP tick ordering or use a small workaround and put Delay node with a tiny value (possibly even 0) just before getting the reference

I was not casting the GameMode correctly. It works now. Thank you very much phoboz :slight_smile:

Can someone explain this using images? “Save their references inside GameMode after spawning, then call GetGameMode inside Level BP, cast to your type and you can get the references.”