Skip to content

Commit

Permalink
fix(WldInsertNpc): If CurrentWP not exists, try with previous one.
Browse files Browse the repository at this point in the history
  • Loading branch information
JaXt0r committed May 31, 2024
1 parent eca2eab commit 54289e4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Assets/GothicVR/Scripts/Creator/NpcCreator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,13 @@ private static void SetSpawnPoint(GameObject npcGo, string spawnPoint)
{
var routineSpawnPointName = npcGo.GetComponent<Routine>().CurrentRoutine.waypoint;
initialSpawnPoint = WayNetHelper.GetWayNetPoint(routineSpawnPointName);

// Fallback: No WP found? Try one more time with the previous (most likely "earlier") routine waypoint.
if (initialSpawnPoint == null)
{
routineSpawnPointName = npcGo.GetComponent<Routine>().GetPreviousRoutine().waypoint;
initialSpawnPoint = WayNetHelper.GetWayNetPoint(routineSpawnPointName);
}
}
else
{
Expand Down
6 changes: 6 additions & 0 deletions Assets/GothicVR/Scripts/Npc/Routines/Routine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,11 @@ public bool CalculateCurrentRoutine()

return changed;
}

public RoutineData GetPreviousRoutine()
{
var currentRoutineIndex = Routines.IndexOf(CurrentRoutine);
return currentRoutineIndex == 0 ? Routines.Last() : Routines[currentRoutineIndex - 1];
}
}
}

0 comments on commit 54289e4

Please sign in to comment.