AI loses sight perception continuously when using Move To node

I have an issue where the On Target Perception Event of the AI Perception component on the controller gets called continuously with the sight stimuli’s Successfully sensed value switching quickly from true to false.

I’m basically using the Move To node to strafe left to right when the AI is in combat mode. However, when reaching the Move To node the Perception Event is triggered with a Successfully Sensed value of false, even though the player always remains in sight (the AI is strafing and it has a vision of 90 degrees), and this is followed immediately by another Successfully Sensed with value true and so on, in a close loop.

This is my configuration:

This is where I check the value:

And this is the result:

If I remove the MoveTo node in my BT, then this behavior stops and the AI does not stop to sense the player unless the player moves away from sight (so, the event On Target Perception Event is no longer raised with a successfully sensed value of false).

You can see here that the node MoveTo is not followed by the wait node, and that’s because the MoveTo resets the Target Actor so the decorator aborts the whole branch:

I’ve seen similar questions in this forum, however no real answer here. Has someone seen this behavior? What can I try to solve it?

Thank you.
r.

I don’t use the perception system often enough to know what all is going on here, but if you are just trying to get an AI to move toward a character it sensed, surely just using normal blueprint variables would still work here?

Every time it senses a character, you can set a variable and then just directly have it move toward that actor in the variable. I would think that should work regardless of if it weirdly decides a split second later that it can’t perceive the character anymore.

That’s not what I need. The character is already sensed and the AI is shooting at them, what I’m doing here is strafing while shooting to make the AI a more difficult target. In the strafing, the MoveTo node makes the sight perception raise a lost sight event, which in turn aborts the whole attack node, and enters this loop.

Hi, your AI perception image above shows 3 configs. OnTargetPerceptionUpdated will fire per sense, so even if the target is plain in sight if e. g. some hearing stimulus reached its age limit it will fire an update with SuccessfullySensed being false also even if there are other still active hearing stimuli for that actor. Don’t know whether that is your problems, but from just checking SuccessfullySensed you can’t make any assumptions about the actor being in sight of the AI or not.

Also you set max age to 0, maybe try a value greater than 0.

Hi, the other two components are disabled. Max Age > 0 doesn’t change the erratic behavior.

Interesting, I guess then I would try to pin it down, but I have no guarantee that that will work. So you could print the Actor to make sure that it is really the player and not something else. Then you can also use GetCurrentlyPerceivedActors and see if the player inside that / gets removed from that. Also you could use GetActorsPerception and check what it currently perceives from the player.

The point is: there’s nobody else to be perceived but the player, and the perception constantly comes and goes. The only way to mitigate this is to set the Auto Success Range from Last Seen Location to a value close to the Perception Range. Thanks for trying to help BTW.

BTW, other similar cases:

If there is only the player and if it is inside the range and vision cone, then it most likely fails due to the trace test. As a last resort you could (in C++) implement the CanBeSeenFrom function of the IAISightTargetInterface in your player character and therefore doing the trace test yourself. As a bonus you can then also set the stimuls strength there (otherwise it will always be 1.0f it is in sight and 0.0f if not).

Also from what I see from the source code is that the default implementation (what it will use if the actor it is tracing against does not implement the IAISightTargetInterface) of the trace check will use the “EyesLocation” of the one who is tracing (the bot in this case) against the actor location of what it traces for (in this case the actor location of the player) and the default collision channel it will use (you can change it in the project settings) is the visibility channel. So also make sure that you have nothing that is not owned by the player that is blocking the visibility channel between player and bot.

I would implement the IAISightTargetInterface, so the CanBeSeenFrom function and as a first step just let it return true and set the OutSeenLocation to the actor location of the player. Then the AI should never loose sight of the player as long as the player is inside its view cone. Then inside CanBeSeenFrom manually do a linetrace and see what it hits.

Thank you @chrudimer, there’s nothing in the actor itself which could interfere with the visibility channel. I’ve also tried setting in every component of the AI and the character to ignore visibility collision, to no avail. Also, changing capsule size on the AI, but AFAIK anyway the center 0,0,0 will be used so that shouldn’t change anything. Will try to see if I can hack my way out of this with C++… thank you.

BTW I’ve already overridden GetActorEyesViewPoint to no avail as well.

My Bad. I had a wrong implementation. This gets actually solved with a proper eyes location, and GetActorEyesViewPoint implemented on the AI. Thank you @chrudimer… Unfortunately cannot accept your answer, if you care to write it I will accept it.

I don’t know the steps you needed to solve the problem, so you solved the problem, not me =)

I wrote things I would check/ how I would try to pin it down and those rather belong into comments. Therefore I guess it would be best if you would write down what you needed to do to solve the problem into an answer and accept that. That would also make it easiest for everyone else who has the same problem and reads this in the future to find a solution.

I will. Thank you for your help.

The whole problem seems to be related to the fact that by defaul the AI Perception component uses the actor center as eyes position for the sight. Even though I tried disabling the Visibility channel on every component that might have been blocking the sight perception, something still seemed to block the proper AI “vision”.

My solution was to override the function GetActorEyesViewPoint called by the AI Controller on the controlled character, and from that function I’m calling a BP function that I can override in the character BP:

Header file

	// Override for AI Perception "Eye" Location
	void GetActorEyesViewPoint(FVector& Location, FRotator& Rotation) const override;

	// AI Eyes function
	UFUNCTION(BlueprintImplementableEvent, Category = AI)
	FTransform GetAIEyesTransform() const;

CPP implementation

void AMyAICharacter::GetActorEyesViewPoint(FVector& Location, FRotator& Rotation) const
{
	FTransform T = GetAIEyesTransform();
	Location = T.GetLocation();
	Rotation = T.Rotator();
}

Now all that is need is to override this function in the AICharacter BP with the desired location / rotation:

Hope this helps others. Thank you @chrudimer for the help.

Try setting Point Of View Backward Offset to 10. It’s in the AIPerception details. Hope that helped!