How to handle when out of AIPerception detection range??

I would like to create a function that detects a player using AI Perception, starts a timer, and stops the timer when the player is out of detection range.

This function is controlled by a behavior tree, but the ``function that stops the timer when the object goes out of the detection range’’ does not work properly.

AIController has nodes like this, but it seems that the False part of the Branch node is not working properly.
(It may be a little small and hard to see…)

Therefore, the variable called Target Actor always has a value, and the node on the right side of the behavior tree is not executed.

The two tasks are simple tasks that allow players to cast and execute events.

Is there any way to solve this problem?
Please let me know if there is anything that is not explained well…

When perception updates due to losing sight of a target, the lost target is still returned as the actor value. You need to split/break the stimulus pin and check the Successfully Sensed bool to see if event was caused by the target “hiding.”

It was possible to determine whether the player was out of the detection range of AIPerception.

However, what I want you to pay attention to is the value of the variable on the right side of the play screen.
I want the number to increase while the player is being detected, and stop increasing when the player is not. However, now the situation is the opposite.

The contents of the two tasks are as follows.


The event called Test in “BT_Task_NotDetection” currently has no function. (As the name suggests, it is a test.)

I’m very sorry, but if there is a way to increment the number only while the player is detected, please let me know.

I think the only real way to see if player is outside of range would be to get the distance between player and the controlled pawn, and manually compare it to whatever your detection radius is set to.

Otherwise, as mentioned above, you can test if a perception update was a success or fail, and use the result to do other things:

This noodle block from an ai controller bp will print hello when it sees player pawn, and goodbye when it loses sight of player. Instead of printing a string, you could set a “CanSeePlayer?” bool on the blackboard or whatever.

Sorry, the issue has been resolved.
Thank you illspiritx!!

The way I did it was simple, I changed “BT_Detection” and “BT_NotDetection”
This method involves swapping them within the behavior tree and changing only the name to make the AI’s movements easier to understand. I don’t know if this method is correct, but I have confirmed that it works.
If there is a better way, I would be very grateful if you could let me know.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.