How can I change the controller that my character uses during gameplay?

I have four instances of the same character blueprint in my level - each of which can be possessed. At level start one is possessed by the player controller and the other three act upon an aicontroller blueprint.

When one of the other instances of the character is possessed by the player controller, the previously possessed character does not currently act upon the aicontroller.

Is there a way to make a character swap from using the character controller to using the ai controller when it ceases being possessed?

Thanks in advance.

All you need to do is implement ReceiveUnpossessed event in your BP Pawn class and when OldController passed with the call is a PlayerController then you need to instantiate new AIController and tell it to posses the pawn in question.

Let me know if you have any more questions.

Cheers,

–mieszko

Hi Mieszko,

I have made some progress but could use a little more help if you don’t mind. This is what I currently have set up in my character blueprint:

With this setup the pawns do not use the ai controller on begin play, they just remain static when they should be moving around.

Also, when a character is unpossessd, all of the pawns (except for the one that is now possessed by the player controller) should begin to use the ai controller, but currently only the one that was previously possessed by the player does this.

Is there a way that I can have all pawns except the one that is possessed by the player use the AI controller on begin play and also have all pawns except for the one that is newly possessed by the player, use it when the previous pawn is unpossessed by the player?

Many thanks,
Joe

It sounds like you’re using SpawnActor to spawn your AI pawns while you should be using SpawnAIFromClass. If you are using SpawnAIFromClass then it sounds like there’s a bug and it would be awesome if you shared your project with us.

Alternatively you can just spawn AIController in pawn’s ReceiveBeginPlay and then call Posses on the controller.

Cheers,

–mieszko