How to swap controllers?

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.

I think it is possible to do this because this event exists.
swap

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.

Thank you so much!!

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/
Maybe you can hook up some automatic functions that will fire / swap brains when it dies?
I hope this can help!
-Zen

1 Like

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… :frowning:

Thanks you so much Zen!!

1 Like

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!!

1 Like

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.

1 Like

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

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

1 Like

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

1 Like

ok it doesn’t seem to work, :sweat_smile:

1 Like

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!!

aa, of course unpossed what a fool I am :man_facepalming:, I think now it works with just only with this

1 Like

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

This worked for me…

Pawn Blueprint Code:

Controller Blueprint Code:

:ok_hand:

1 Like

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

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

interesting I use these two nodes only

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?

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

The second time it was only repossessed by the controller

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…

Nope, I guess it depends on the force used

maybe the unpossed stop the brain, and you just have to do a restart.
image
These functions stop and activate the BT

1 Like

Thanks a lot!! finally everything works fine!!

1 Like