UE5.3 C++: OnTargetPerceptionForgotten Delegate not Firing

After much digging, I finally solved your (our) problem!

The problem with setting bForgetStaleActors with the GetCurrent() method in BeginPlay is that by then it’s too late to actually matter.

You see, the UAIPerceptionComponent class does not use bForgetStaleActors from UAISystem, but it’s own bForgetStaleActors that it sets on its constructor with this line:

bForgetStaleActors = GET_AI_CONFIG_VAR(bForgetStaleActors);

What it does is getting the value of the variable from the default object class, not the one you changed in BeginPlay.

To solve this, you can edit your DefaultEngine.ini inside the Config folder of your project and add these two lines:

[/Script/AIModule.AISystem]
bForgetStaleActors=True

This way, the variable will be initialized to True from the start and OnTargetPerceptionForgotten will work as expected.

3 Likes