How to resume roaming after MaintainFocus?

So, I have an NPC that will give focus to the player when a button is pressed. This is working fine with the code below:

OnConvoButtonPressed(Agent : agent) : void=
        Print("Convo button pressed!")
         # When a character spawns, have them focus on the first player in the playspace
         if:
            FortCharacter := SavedAgent?.GetFortCharacter[]
            FocusInterface := FortCharacter.GetFocusInterface[]
            #GuardInterface := FortCharacter.GetFortGuardActions[]
            NPCBehaviorInterface := SavedAgent?.GetNPCBehavior[]
            PlayerToFocus := GetPlayspace().GetPlayers()[0]
        then:
            Print("Found the NPC to focus with!")
            spawn{FocusInterface.MaintainFocus(PlayerToFocus)}

How do I tell the NPC to stop focusing on the player and go back to roaming around as it was by default?

Hi! According to the docs, MaintainFocus will never complete unless interrupted. So, you need to run it in an async context and ensure that something else cancels the focus.

For instance:

race {
    FocusInterface.MaintainFocus(PlayerToFocus)
    Sleep(3.0)
}

This will end the focus after 3 seconds. You could also await an event, such as the player leaving an area—it really depends on how you want to cancel the focus.