Download

How to change the PlayerController during runtime?

Heyho, Im just getting started with Unreal and Im kinda lost as I find the official documentations totally not helpful. This is my situation:

I want to create an asymmetrical multiplayer game and I just want to test a few things for now. Lets say theres the good guys and the bad guys. For testing purposes I wanted to create a little level where I can switch between the roles. So I made another blueprint with a trigger box and two copies of the default thirdperson character. (One for the good guys and one for the bad guys)
The idea is that when I run into the trigger box as a good guy the good guy actor gets destroyed, a bad guy actor gets spawned and I control the bad guy now. Since they both derive from the standard third person blueprint they are controllable characters and when I spawn them in by setting the “DefaultPawn Class” to my good guys it works. I can run around as a good guy. And I managed to spawn bad guys when I step on my trigger. However I am absolutely clueless as to how I let the game posses this newly spawned bad guy. I saw there used to be some kind of posses/unposses functions in UE but they seem to be heavily outdated. Im running version 4.23.0

My idea was to use the “enable” input function on the newly spawned character. But it demands to know which player controller should be used of course. I found functions to get the player controller from an index, but not how to get that index from a character. Soooooo how do I tell the Engine that the player controller that was responsible for the good character i stepped in my trigger volume with is now responsible for the newly spawned bad guy?

And keep in mind this needs to be Mulitplayer useable.
And if you guys have some advice on good online sources explaining GameModesGameModes and PlayerControllers for UE4 further then Id really appreciate if you could send that my way. Im used to the official Unity documentation which is great because it also always provides examples on how to use each function. But im totally lost with Unreal tbh…
Help is much appreciated!

As far as I am aware, the possess nodes work just fine - I use them regularly (In 4.22 but I don’t believe they’ve been removed in 4.23).

UE4 knows this already. Once you are connected to a session, you will have a persistent player controller. Even if your controlled pawn is deleted you will keep the same controller. My suggestion would be to

  1. Spawn a new pawn (for the “baddie”)
  2. In your player controller, use the “Possess” node to change your possessed pawn from the old pawn to the new one
  3. Destroy the old pawn

I also want to know how to switch from a PLayer controller to an AI controller on my player character.
EG: player character dies and ragdolls . then an AI controller takes over the same character and starts to control them.

I dont want to destroy my Character and spawn a new character that dosent look like them.

Is this possible?

Sure, I believe if you have the AI controller simply possess the character’s pawn, the player will be “ejected” from the pawn.

That sounds simple enough :slight_smile: But would the AI controller have to already be in the world or could I have it set so that one would be created and then possess the character.

I imagine you’d want to create a new AI controller to possess the pawn (assuming you’re not trying to use an existing AI controller to use un-possess another pawn then possess the new one)