# How to swap controllers?

**URL:** <https://forums.unrealengine.com/t/how-to-swap-controllers/667413>\
**Category:** AI\
**Tags:** unreal-engine, UE5-0, Blueprint, question\
**Created:** [October 11, 2022, 6:04pm UTC](https://forums.unrealengine.com/t/how-to-swap-controllers/667413 "2022-10-11T18:04:30Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ivan3z](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Ivan3z](https://forums.unrealengine.com/u/Ivan3z)\
**Post date:** [October 11, 2022, 6:04pm UTC](https://forums.unrealengine.com/t/how-to-swap-controllers/667413/1 "2022-10-11T18:04:30Z")

</div>

I want to exchange the **“Crowd AI Controller”** for the **“AIController”** at runtime.  
However, I can’t find any information on how to do this.

Because I have the same problem shown in this post.

> [@Crowd AI Controller - capsule collision](https://forums.unrealengine.com/t/crowd-ai-controller-capsule-collision/462661):
>
> Hello Gods of UE4! So Im using crowdAIcontroller, my AI is having trouble to walk over another dead AI, when the AI gets killed, Im setting collision disable to capsule and mesh, and additionally setting the capsule to ignore collision response to all channels. Theres no other item with collision set in the actor. The AI doesnt get stuck, but looks like its really hard to find the path, and it goes really slow over the dead body. Mesh is set to can ever affect navigation to true Capsule is s…

I think it is possible to do this because this event exists.  
 ![swap](https://d3kjluh73b9h9o.cloudfront.net/original/4X/a/0/2/a022dd0983eed15d9b2b51b49546eb2205647ec0.png)

But his solution doesn’t work for me because I don’t want to destroy the pawn… I’m recycling it… I think recycling is more efficient than respawning a new one.

Does anyone know how to swap controllers?  
Or failing that, fixing the capsule problem in another way could also be a valid solution for me…

This is my setup for the capsule of the dead. It works fine for clients and server but fails with AI.

 ![config](https://d3kjluh73b9h9o.cloudfront.net/original/4X/6/c/c/6ccd99215c48471a81b8cabf42defbbf4cdaafba.png)

Thank you so much!!

---

<div class="post-metadata">

**Author:** ![ZenLeviathan](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/zenleviathan/32/551307_2.png) [@ZenLeviathan](https://forums.unrealengine.com/u/ZenLeviathan)\
**Post date:** [October 11, 2022, 7:03pm UTC](https://forums.unrealengine.com/t/how-to-swap-controllers/667413/2 "2022-10-11T19:03:48Z")

</div>

Hey @Ivan3z  
Have you looked at the AI Module Unreal has in its API? It has a pretty easy way to switch brains and execute other functions. Here is a link to help get started,  
[https://docs.unrealengine.com/4.26/en-US/API/Runtime/AIModule/BehaviorTree/UBehaviorTreeComponent/](https://docs.unrealengine.com/4.26/en-US/API/Runtime/AIModule/BehaviorTree/UBehaviorTreeComponent/)  
Maybe you can hook up some automatic functions that will fire / swap brains when it dies?  
I hope this can help!  
-Zen

---

<div class="post-metadata">

**Author:** ![Ivan3z](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Ivan3z](https://forums.unrealengine.com/u/Ivan3z)\
**Post date:** [October 11, 2022, 7:27pm UTC](https://forums.unrealengine.com/t/how-to-swap-controllers/667413/3 "2022-10-11T19:27:03Z")

</div>

Hi Zen!!

I’ll take a look at it.  
Although the real problem is not the behavior tree.  
The problem is the capsule component.  
For some reason the collisions still working even though I disabled them. (for AIs Only)

So when the AI dies its weapon is detached.  
And for 5 seconds it is trapped inside the capsule.  
Then the other AIs collide with the capsule and they can’t catch the weapon easily.

In the post I attached above, It said that the problem with the capsule is caused by the controller… **“Crowd AI Controller”**. And if the **“AIController”** controller is used, this problem does not exist.

Everything would be easier if I could just make the capsule disappear for 5 seconds.  
But it does not simulate physics either… ☹

Thanks you so much Zen!!

---

<div class="post-metadata">

**Author:** ![Ivan3z](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Ivan3z](https://forums.unrealengine.com/u/Ivan3z)\
**Post date:** [October 11, 2022, 8:09pm UTC](https://forums.unrealengine.com/t/how-to-swap-controllers/667413/4 "2022-10-11T20:09:45Z")

</div>

Yes, the problem was definitely with the controller. If I use “AIController” there is no problem with the capsule. I did my own avoidance task using EQS and that way I more or less get the pawns not to collide with each other.  
'll use this until a better solution comes along.

Thx u so much Zen!!

---

<div class="post-metadata">

**Author:** ![eblade](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@eblade](https://forums.unrealengine.com/u/eblade)\
**Post date:** [October 11, 2022, 8:49pm UTC](https://forums.unrealengine.com/t/how-to-swap-controllers/667413/5 "2022-10-11T20:49:06Z")

</div>

So, the difference between AIController and DetourCrowdAIController, is that AIController gets a regular PathFollowingComponent, while DetourCrowdAIController gets a CrowdFollowingComponent.

There are many functions inside CrowdFollowingComponent that you can probably mess around with to enable/disable any functionality in there on the fly.

My _guess_ is that if you SetCrowdSimulationState(ECrowdSimulationState::Disabled) on the _corpse’s controller_ when it dies, it’ll switch to being ignored by the remaining pathfinders, and probably force an update to any of the other pathfinders that are trying to avoid it. I’m _not_ sure about that, as I’ve never actually used it. You might need to call it (or SuspendCrowdSimulation()) on the AIs that you want to be able to go through it now, until it is disappeared.

This is all theory. You might want to have a look at CrowdFollowingComponent.h/.cpp to see what it looks like in there.

---

<div class="post-metadata">

**Author:** ![Ivan3z](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Ivan3z](https://forums.unrealengine.com/u/Ivan3z)\
**Post date:** [October 11, 2022, 10:28pm UTC](https://forums.unrealengine.com/t/how-to-swap-controllers/667413/6 "2022-10-11T22:28:07Z")

</div>

Ok, I’ll take a look at that. Thank you so much for the idea!!

---

<div class="post-metadata">

**Author:** ![ZenLeviathan](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/zenleviathan/32/551307_2.png) [@ZenLeviathan](https://forums.unrealengine.com/u/ZenLeviathan)\
**Post date:** [October 12, 2022, 5:08pm UTC](https://forums.unrealengine.com/t/how-to-swap-controllers/667413/7 "2022-10-12T17:08:23Z")

</div>

@Ivan3z  
Post again if you have any more questions! Happy Developing! 🖖  
-Zen

---

<div class="post-metadata">

**Author:** ![DomusLudus](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/domusludus/32/1215140_2.png) [@DomusLudus](https://forums.unrealengine.com/u/DomusLudus)\
**Post date:** [October 13, 2022, 1:41pm UTC](https://forums.unrealengine.com/t/how-to-swap-controllers/667413/8 "2022-10-13T13:41:51Z")

</div>

> [@Ivan3z](#):
>
> Does anyone know how to swap controllers?

I realized this same problem but I hadn’t started looking for a solution yet, since my project is blueprint only and DetourCrowdAIController has absolutely nothing exposed, ZenLeviathan’s solution cannot be used  
But what you workaround is perfect.  
You just have to spawn a controller and pose the character

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/1/7/c/17ce6b1bdd760bcf92bd11277c606f17a0a6eb6e.png)

---

<div class="post-metadata">

**Author:** ![DomusLudus](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/domusludus/32/1215140_2.png) [@DomusLudus](https://forums.unrealengine.com/u/DomusLudus)\
**Post date:** [October 13, 2022, 3:47pm UTC](https://forums.unrealengine.com/t/how-to-swap-controllers/667413/9 "2022-10-13T15:47:19Z")

</div>

ok it doesn’t seem to work, 😅

---

<div class="post-metadata">

**Author:** ![Ivan3z](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Ivan3z](https://forums.unrealengine.com/u/Ivan3z)\
**Post date:** [October 13, 2022, 4:14pm UTC](https://forums.unrealengine.com/t/how-to-swap-controllers/667413/10 "2022-10-13T16:14:44Z")

</div>

OK, no problem!!  
I haven’t tried this but you’ve given me an idea…  
Maybe dispossessing the pawn while it’s dead and then repossessing it with the same controller will work…  
Obviously this would have to be done from the Game Mode…  
i will try it!!  
Thank you very much!!

---

<div class="post-metadata">

**Author:** ![DomusLudus](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/domusludus/32/1215140_2.png) [@DomusLudus](https://forums.unrealengine.com/u/DomusLudus)\
**Post date:** [October 13, 2022, 4:24pm UTC](https://forums.unrealengine.com/t/how-to-swap-controllers/667413/11 "2022-10-13T16:24:27Z")

</div>

aa, of course unpossed what a fool I am 🤦‍♂️, I think now it works with just only with this

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/6/a/d/6ade6e01aa12369e5c61b9702408103af1127589.png)

---

<div class="post-metadata">

**Author:** ![Ivan3z](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Ivan3z](https://forums.unrealengine.com/u/Ivan3z)\
**Post date:** [October 13, 2022, 4:31pm UTC](https://forums.unrealengine.com/t/how-to-swap-controllers/667413/12 "2022-10-13T16:31:10Z")

</div>

I will try it… although the idea is not to destroy the pawn so that it can be reused later

---

<div class="post-metadata">

**Author:** ![Ivan3z](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Ivan3z](https://forums.unrealengine.com/u/Ivan3z)\
**Post date:** [October 13, 2022, 6:06pm UTC](https://forums.unrealengine.com/t/how-to-swap-controllers/667413/13 "2022-10-13T18:06:48Z")

</div>

This worked for me…

Pawn Blueprint Code:

 ![pawn](https://d3kjluh73b9h9o.cloudfront.net/original/4X/3/b/a/3ba3ca2964fe7266949eba5a605ed1fd4d641fd4.png)

Controller Blueprint Code:

 ![controller](https://d3kjluh73b9h9o.cloudfront.net/original/4X/f/1/4/f14abf13bb65fa3d09cca42461e5bdbd7564c658.png)

👌

---

<div class="post-metadata">

**Author:** ![DomusLudus](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/domusludus/32/1215140_2.png) [@DomusLudus](https://forums.unrealengine.com/u/DomusLudus)\
**Post date:** [October 13, 2022, 6:12pm UTC](https://forums.unrealengine.com/t/how-to-swap-controllers/667413/14 "2022-10-13T18:12:44Z")

</div>

nice for you, btw i just destroy the controller, the pawn stays in the game to simulate the ragdoll.

---

<div class="post-metadata">

**Author:** ![Ivan3z](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Ivan3z](https://forums.unrealengine.com/u/Ivan3z)\
**Post date:** [October 13, 2022, 6:17pm UTC](https://forums.unrealengine.com/t/how-to-swap-controllers/667413/15 "2022-10-13T18:17:17Z")

</div>

yes, of course… that’s the idea!! Before dispossessing the pawn you must set up the mesh. This is my setup.

 ![ragdoll](https://d3kjluh73b9h9o.cloudfront.net/original/4X/0/9/2/09284bffb40f2835975b41f01a16a5eb720decf9.png)

---

<div class="post-metadata">

**Author:** ![DomusLudus](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/domusludus/32/1215140_2.png) [@DomusLudus](https://forums.unrealengine.com/u/DomusLudus)\
**Post date:** [October 13, 2022, 6:28pm UTC](https://forums.unrealengine.com/t/how-to-swap-controllers/667413/16 "2022-10-13T18:28:46Z")

</div>

interesting I use these two nodes only

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/a/2/0/a20e1f53bfb46094482e54155e45dfb8e728b56e.png)

---

<div class="post-metadata">

**Author:** ![Ivan3z](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Ivan3z](https://forums.unrealengine.com/u/Ivan3z)\
**Post date:** [October 13, 2022, 6:51pm UTC](https://forums.unrealengine.com/t/how-to-swap-controllers/667413/17 "2022-10-13T18:51:48Z")

</div>

yes, I tried that too… the problem was that sometimes the pawn flew very far… sometimes it even went through walls. With the configuration I have now that does not happen.  
don’t have you that problem?

---

<div class="post-metadata">

**Author:** ![Ivan3z](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Ivan3z](https://forums.unrealengine.com/u/Ivan3z)\
**Post date:** [October 13, 2022, 11:36pm UTC](https://forums.unrealengine.com/t/how-to-swap-controllers/667413/18 "2022-10-13T23:36:24Z")

</div>

For some reason after possessing the pawn for the second time the behavior tree refuses to work. Possession succeeds but the tree doesn’t work…

Do you have any idea why this happens?

i’m doing it like this.

The first time it was spawned from game mode.  
 ![1Spawn](https://d3kjluh73b9h9o.cloudfront.net/original/4X/9/f/c/9fc0282cdb66248f14e10081b0a03c8696945487.png)

The second time it was only repossessed by the controller

 ![BT](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/b/5/7b5cf519f740193934442f0f2fc0f443b1971895.png)

I’m starting to think that it’s just much easier to use AIControler instead of the Detour Crowd AIController…it’s more trouble than it’s worth…

---

<div class="post-metadata">

**Author:** ![DomusLudus](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/domusludus/32/1215140_2.png) [@DomusLudus](https://forums.unrealengine.com/u/DomusLudus)\
**Post date:** [October 14, 2022, 4:27am UTC](https://forums.unrealengine.com/t/how-to-swap-controllers/667413/19 "2022-10-14T04:27:32Z")

</div>

> [@Ivan3z](#):
>
> don’t have you that problem?

Nope, I guess it depends on the force used

> [@Ivan3z](#):
>
> Do you have any idea why this happens?

maybe the unpossed stop the brain, and you just have to do a restart.  
 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/b/6/4/b640a248c5f381f31760cbd79f3754dfbe378638.png)  
These functions stop and activate the BT

---

<div class="post-metadata">

**Author:** ![Ivan3z](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Ivan3z](https://forums.unrealengine.com/u/Ivan3z)\
**Post date:** [October 14, 2022, 11:25am UTC](https://forums.unrealengine.com/t/how-to-swap-controllers/667413/20 "2022-10-14T11:25:23Z")

</div>

Thanks a lot!! finally everything works fine!!

[Next page](https://forums.unrealengine.com/t/how-to-swap-controllers/667413.md?page=2)
