AAIController SetFocus() invalid location

if you call SetFocalPoint() with a world position
then later call SetFocus() on an Actor (never calling ClearFocus)
if that Actor happens to be destroyed the WeakPointer will be cleared
and the code falls back to using the old location

I’d recommend SetFocus() always reset the Position to InvalidLocation

Hello pci,

Could you provide a simple repro for this issue, whether it is a set of steps or a small project? I tried setting up something of my own real quick but didn’t see the issue that you mentioned.

here’s a simple blueprint that I placed on a character
the character will initially face world location -5000,-5000
after 2 seconds it faces an actor of whatever class you like
after 2 seconds that actor is destroy
the character strangely turns back toward the old world point

I expect the old point to be clear and after destroying the focus object the character would continue facing their current direction.

Paul

My recommended fix is simple…

void AAIController::SetFocus(AActor* NewFocus, EAIFocusPriority::Type InPriority)
{
if (NewFocus)
{
if (InPriority >= FocusInformation.Priorities.Num())
{
FocusInformation.Priorities.SetNum(InPriority + 1);
}
FocusInformation.Priorities[InPriority].Actor = NewFocus;
FocusInformation.Priorities[InPriority].Position = FAISystem::InvalidLocation;;
}
else
{
ClearFocus(InPriority);
}
}

Thank you for providing that. It’s also good to see that you have a proposed fix. Seeing as the current functionality could be intended and I’m not exactly sure if this is a bug, it may be best if you were to submit a Pull Request on Github to fix the issue instead. If you do this, the proposed fix will be reviewed and considered for integration.

If you would rather not make a pull request however, please let me know and I’ll put in a bug report for you myself.

I haven’t used GitHub much and don’t know about PullRequests – it seems more accidental than intended – if you focus on one actor then a second that gets destroyed it does not revert to the previous focus actor. I’ll let y’all decide what to do. I can work around it by always calling ClearFocus() before SetFocus() calls. Thanks for the response.

I’ve placed a bug report in for this issue. For reference, the number is UE-27975. I’ll be sure to let you know if any updates are made. While I’m still not sure if this is intended to work this way or not, we’ll know for sure soon.

As a quick update, I checked in a fix for this today, similar to your suggestion. It should appear in 4.12. Thanks for the report and suggestion!