Hi, I want to something when AIPerception component forget an actor. For example, one actor was left the perception range and the age also expired, then the AIPerception component will trigger an event to do something. Is there any good way to do like so? Or is there already defined a delegate that I can bind my event? Thanks for any advice.
I donāt think there is an Event for that.
What you could do: Use āget known perceived actorsā
store the length. And Update it once every 0.3seconds or something.
And if the value decreases you know that one of the actors was destroyed or expired.
Last time I used get known perceived actors, it didnt work properly for specific senses so Iād carefully track the values with the AI Debugger before you fully integrate a feature like that.
Hi PascalSantos,
Iād thought a solution very similar to yours, but I think to check this in tick function in each frame is not so efficient. So I came here to look for is there a better solution. If no, maybe I can do this in c++ myself and create a pull request to the engine repo on github.
I was struggling with this a few months ago too, finally I have found the solution! (Iām using 4.23 now)
-
Set up your custom UAIPerceptionComponent C++ class derived from the original one.
-
Override the virtual function:
virtual void HandleExpiredStimulus(FAIStimulus& StimulusStore) override;
-
Do something in the cpp file! Note that you should not call Super:: method there!
-
Add your custom UAIPerceptionComponent to your AIController. Thatās it!
Hopefully it helps!
The solution is simple go to the project setting, Under Engine - AI System, there is a check for āForget Stale Actorsā. Have it checked and then you can use āOn Target Perception Forgotten (AI Perception)ā from the AI perception component.