How do I disable AI until triggered?

I have an ambush I want to set up that only happens if the player doesn’t do something, so I want to hide and disable the AI so that if they do what I want them to they never know those AI were. However, if you mess up they become visible and enable the AI (and tell the AI to move in but I’ve got that part) and they teach the player that lesson. It’s the disabling the AI so that it’s not getting on to the player until triggered that I’m trying to figure out.

Not sure, if you already use them. In case you don’t, Behaviour Trees will definitely help you here.
Check out that great tutorial by Mathew Wadstein WTF Is? AI: Behavior Tree in Unreal Engine 4 ( UE4 ) - YouTube

2 Likes

Hello mclark4386, thank you for posting.

I agree with herb64’s response on the behavior tree guide. I will also place the documentation here for later reference if you need it.

To address your question: It really depends on what you intend for the AI to do before you need them to function. If you do not want them in the level at all, you could always consider “Spawn Actor from class”.

Either way, I would consider a behavior tree.

I hope herb64 and I helped you.

1 Like

We have multiple AI’s with complex BTs. I suppose I could add a variable to the blackboard to basically pause the tree until the bool is unchecked… I figured there was a better way to do it like that, like turning of the AI tick or something like that, but wanted to ask in case there was a more standard built in way of doing it.
The use case is that we have complex AI with a bunch of settings that I want my level guy to set (so he is placing them in the level), BUT when the player starts the game it should be like they aren’t in the level and then if they trigger the ambush it “spawns” them. The problem is I don’t want to use spawn because of all the settings that need to be set… not really tenable. Just to be clear, it’s possible that the player NEVER triggers the ambush, so I need to make sure it’s like they aren’t there (not as worried about performance, most worked about the player getting killed by invisible AI ).
Does that make sense?

Hey @mclark4386. I think there are many ways for you to handle stopping your AI. I recommend adding a custom StopAI() method to your AIController so that you have control over the steps needed to correctly stop your AI behavior.

BehaviorTrees have a method StopTree(), maybe you could start trying that. You could also try to have your enemy units start Unpossessed, which means that there is no AIController attached to them and then call Possess() in the AIControllers to take control of those units and start the behavior there. Any other custom behavior that you may have should be manually stopped.

The method of creating a bool in the behavior tree and using that to stop the execution is also valid though, but as you said, it might not be the cleanest solution. In the end what matters is that you remain consistent in the way you handle your AI. Since you probably will have many different BehaviorTrees I would suggest trying a different way to stop the behavior.

Hope this helps

1 Like

Easiest thing to do is just not start running their behavior tree until you need them.