Changing AI controller for actor?

Hello everyone!

So I am doing this small NPC project, where I need to change the AI controller of NPC.

I used “Set AI Controller” to set it on “Event BeginPlay” and spawned the default controller, but that doesn’t work when I try to change it…

This is how my code looks for setting the AI controller for the first time :

set_controller_deer_child

And this is when I try to change it:

set_controller_deer_male

I read on Reddit that “Controller controls Actor” and not vice versa, but I feel like this could be done. I mean to change the controller…

Hopefully, I can get the answer…

Thanks In advance!

Hi :grinning: So my solution is this: in your possessed pawn blueprint destroy your current ai controller, then spawn a new one and possess your pawn. The issue with ai controllers is that you could not destoy them in blueprints by destoyActor node, so the work around is to use SetLifeSpan with a small duration( you could read the discussion here Ai controller can never be destroyed or be garbaged collected - #16 by acatalept). The way I would solve your problem is this:


Hope this helps

1 Like

Hi! Thanks for helping me once again! I get the logic of this thing, I just didn’t know these functions, thanks for telling me about those two functions.

Aside from that, I am getting this weird error, I tried re-doing this sequence of a blueprint a few times, but I can’t quite help it. Any idea about it?

Thanks in advance!

Edit: oops forgot to attach a photo xd

EDIT N2: Oh I’m so stupid, I forgot to attach the Transform, now it works like a charm! Thanks a lot!