Download

Switch between Player/AI controllers

Hi there, I’m trying to make a set-up which allows the player to switch pawns. I’ve managed to make a system which cycles through the pawns and makes the player controller possess the desired pawn. That’s all fine and dandy. When a pawn is un-possessed by the player controller, I want it to go back to being controlled by it’s default AI controller. How can I do this?

Here is an image of my switch function, which works well. It’s in the player controller.

bc7fb8581f2507692890796a96962d3e340eaade.png

Then the pawns settings.

PCSSettings.png

I added this to the pawns blue print. This actually works. There is one issue though. It seems as though all four AI controllers are running all the time, even when it isn’t possessing the pawn.

Getting close though!

PCSPawn.png

@Cypher2012 Thanks, been looking for a viable solution for this all day. When you say the AI controllers are running all the time do you mean the behavior trees? I have not set up mine yet but have you found a solution to stop the AI controller from running, or is it a non-issue?..just looking ahead.

@Cypher2012 That’s because you need to destroy the Controller actor and safely detach from it. I created two AI_Controller classes, one with detour crowd while the other one is plain simple, and switch them via a custom event that I bound to key event dispatcher on the player pawn.