[STABILITY] NPC behaviour has changed/broken for existing maps

hey friends, I was able to get my navigation working by moving the declaration of my NPC’s navigation_target outside of the scope of the NavigateTo() function, and making it an uninitialized variable instead of a const. Then I set it in a race between it and a Sleep function. My NavigateTo function looks like this now :

#Moved to outside of NavigateTo()
  var NavTarget : navigation_target

    NavigateToNextPatrolPoint(Agent : agent, Navigatable : navigatable) <suspends>: void = 

        loop:
            # Get a vector 3 from our array of Goal Destinations
            if(GoToPoint := GoalDestinations[CurrentPatrolPoint]):

                # Debug meessage
                if(ShowAINavDebug?):
                    Print(first_npc_behavior_message_module.OnNavigateBeginMessage(Agent,GoToPoint.X,GoToPoint.Y,GoToPoint.Z), ?Duration := AIDebugDrawTime)

                
                **# Create a Navigation Target from the next Goal Destination - added race to ensure it is set before proceeding**
**                race:**
**                    block:**
**                        set NavTarget = MakeNavigationTarget(GoToPoint)**
**                        Navigatable.Wait(?Duration := 0.0)**
**                    Sleep(Inf)**
                    
                # If the debug flag is enabled draw a box around the location the NPC is moving toward for visual
                # validation that it is where you expect.
                if(ShowAINavDebug?):
                    DrawDebugLocation(GoToPoint)
                
                NavResultGoTo := Navigatable.NavigateTo(NavTarget, ?MovementType:= movement_types.Running, ?ReachRadius := ReachRadius)
                if (NavResultGoTo = navigation_result.Reached):

                    # Check if final patrol point has been reached and end loop
                    if(CurrentPatrolPoint = GoalDestinations.Length-1):
                        if(ShowAINavDebug?){Print("Final Patrol Point reached")}
                        return
                    # Otherwise increment the patrol point tracker and re-run this function
                    else:
                        set CurrentPatrolPoint += 1

                # Check to see if something has interfered with the NPC reaching the intended location and print a
                # message to the output log.
                else if (NavResultGoTo <> navigation_result.Reached):

                    if(ShowAINavDebug?):
                        Print(first_npc_behavior_message_module.OnNavigateErrorMessage(Agent,GoToPoint.X,GoToPoint.Y,GoToPoint.Z), ?Duration := AIDebugDrawTime)
                        PrintNPCB("Creep Blocked!")

EDIT : Although my fix did patch the navigation issues, unfortunately I found a bug in testing: the NPCs that are blocked by a player built wall will only attack the wall 1 time in attempt to path through it, after which they stop trying. Before the bugs, the NPCs would attack indefinitely until the wall was destroyed and they could continue on their path.

Will be trying working on that one later but I think I’ve done all I can in regards to this issue

5 Likes