[Blueprint] Controlling (Possessing) a newly spawned Pawn,

Hi,

In the game some guys and I are working on, we have a sort of companion sytem, where you have different companion characters, you can choose from, which you can then control and move around with in the Level.
It should work like this: You choose a companion from your inventory, the companion gets spawned and then you can control him for some few basic actions. After that, you control your default player character.
What I have is the inventory system you can choose from (after you collected the companions), which will the spawn a Pawn Actor. But the control switch I couldn’t get implemented, because the level Blueprint (where I change the Possessing of the Player Character and the companions) couldn’t get a reference to the Pawn Blueprint, that wasn’t in the world on the beginning of the Play. It has to get spawned, but when I turn that into a variable, it doesn’t work either.
On the other side, I can control the companion, if I just drag him into the world, reference him from the level Blueprint and change the possession on a Key Press.

Maybe it’s something really simple that I’m missing. I hope you can help me. :slight_smile:
Thanks in advance!,

First of all level blueprint is for level scripting, stuff you talking about seem to be more fitting to GameMode class. Post you level blueprint because we won’t know whats wrong

Hi, thanks for taking the time. :slight_smile:
So in my Level Blueprint there ist not much yet. I thought, I had to do it in there, since in the Unreal documentation in the part about “possessing a pawn”, they do it in the level blueprint too. It’s more or less like that “getting into a car and driving it” example, I think. But without the car (in this case the companion character) already in the scene.
If I’m going all wrong about this, please correct me, I’m happy to learn. :slight_smile:
The second picture is a part of the Pickup Blueprint which gets added to your inventory and which you can use to spawn the actual companion.

Spawning and possessing an Actor.
In your MyCharacter blueprint (or whatever it’s called for you) spawn the companion and spawn a default controller, then possess it. Like so:

Sending variables to the spawned Actor.
To send variables to the spawned companion, first open Companion blueprint and create a Custom Event (I named mine Receive Data) and add the inputs for the variables you want to send over by selecting the Custom Event in the Companion blueprint and in the details panel you will find a tab called Inputs. Then drag off the return value of the SpawnActor node and put a Cast To Companion node with the return value as the object and call the previously created custom event. Then possess the companion.

You might have to put a reference to self as target for the Get Controller node to get it to work.
If the possess fails somehow, adding in a delay before the Possess might solve the problem.
Hope this helps you somewhat.

1 Like

Hey QuantumRSN,

thank you so much. That was exactly what I needed. Now I don’t have to drop the companions in my level and hide and unhide them anymore. :slight_smile:

You’re welcome :slight_smile:

Does this still work? I’m trying to spawn an actor and possess it from my Game Mode blueprint. When I try to connect the Return Value from my Spawn Actor node to the In Pawn value of my Possess node, it tells me “Actor Reference is not compatible with Pawn Reference.”

I’ve been getting around this by using Get All Actors of Class node to find the pawn, and hooking that up to the Possess Node, but the index values seem to change, and it just seems less precise that way.

The Blueprint has to be of the type “Pawn” in order to be possessed. It can’t be an Actor.

That did it! The variable I was putting into Class input on Spawn Actor node was actor type. I changed the type of the variable and it worked. Thanks!