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.

There is the GetAllActors of class node, but if you are spawning them just put them in your list right after they spawn. The reference to the new actor is a pin on the output of the spawn actor node, then add that to your list.

If you spawn the Characters, you don’t need the LevelBlueprint.
Like @mikepurvis said, save the actors into a list (Array) directly after spawning.
Then you can setup a simple switch Pawn system in your “PlayerController” that just
gets the Array from the GameMode.

Normally, you don’t need the LevelBlueprint/GetAllActorsOfClassNode in your game.
If you use it, you should think about a proper way to :smiley: (which is what you do with this thread, so thumbs up!)

Hi guys,
thank you both for answering, and sorry for this late reply.
I’ve been trying not to use the Level Blueprint, as you suggested, but I’m not being able to figure out how to make this list/array, could you guys show me an example?
Thanks in advance.

You said you spawn your Characters in your GameMode.
Each “SpawnActor” node should have a Return Value.

Create an Array of type “Pawn (Reference)” and add the return value of the “SpawnActor” node
to it. Then it will (in theory), have 4 entries in the exact same order as you added them.

Then you can always use “GetGameMode->PAWNARRAY (What ever name you gave it)” and
use “Get” on it with a number from 0-3 (programming starts counting at 0, not 1! And you said you have 4 Characters).

This will then give you one of the 4 spawned pawns that you can call “Possess” on. So no need
for the LevelBlueprint.

Hi eXi, I was able to make it work in the end. Thank you very much for the assistance! :slight_smile:

Awesome! (: