I want the AI to run a sequence only on the frame it sees the player

SuperWhimsy

New member
Hi there, so I'm trying to make it so when my AI enemy sees the player, it doesn't pursue right away, but rather stops moving, turns its head to look at the player, waits a second or two, and then starts pursuing the player. It seems like I need to check every frame if the enemy can see the player, which makes sense, but I don't want this sequence of actions to run every frame it sees the player, just that first frame when it initially sees the player. Should I not put a repeater at the top of my behavior tree? Should I not use a repeater at all? I tried sending an event but realized that Has Received Event doesn't mean it just received the event this frame, but rather that it has received the event at all at some point in the past, so that doesn't help me. I made a boolean variable JustSawPlayer, and tried to make another branch of the tree that checks every frame if the enemy can see the player, and communicates with my code to set that variable to true only if the boolean value just changed this frame. But the overarching issue I seem to keep running into is that I'm checking a variable value every frame, but want to only set this sequence of actions in motion once, when the enemy sees the player. Hope I'm making sense, I'm also somewhat of a beginner to behavior designer, so I'm sure there's stuff I don't know that I could be using here. Any help is greatly appreciated, thanks!
 
Using a bool is the correct route. It's only a single check so you'll never notice a performance bottleneck from this check. With that said, checking a boolean is quicker than using a raycast for Can See Object so I would first check the bool before doing the can see check.
 
Top