From 54289e4b93bc7af4e50706097fe6b6d17c4caf62 Mon Sep 17 00:00:00 2001 From: JaXt0r <120568393+JaXt0r@users.noreply.github.com> Date: Fri, 31 May 2024 05:42:39 +0200 Subject: [PATCH] fix(WldInsertNpc): If CurrentWP not exists, try with previous one. --- Assets/GothicVR/Scripts/Creator/NpcCreator.cs | 7 +++++++ Assets/GothicVR/Scripts/Npc/Routines/Routine.cs | 6 ++++++ 2 files changed, 13 insertions(+) diff --git a/Assets/GothicVR/Scripts/Creator/NpcCreator.cs b/Assets/GothicVR/Scripts/Creator/NpcCreator.cs index 33d3c0952..ec7581bd8 100644 --- a/Assets/GothicVR/Scripts/Creator/NpcCreator.cs +++ b/Assets/GothicVR/Scripts/Creator/NpcCreator.cs @@ -115,6 +115,13 @@ private static void SetSpawnPoint(GameObject npcGo, string spawnPoint) { var routineSpawnPointName = npcGo.GetComponent().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().GetPreviousRoutine().waypoint; + initialSpawnPoint = WayNetHelper.GetWayNetPoint(routineSpawnPointName); + } } else { diff --git a/Assets/GothicVR/Scripts/Npc/Routines/Routine.cs b/Assets/GothicVR/Scripts/Npc/Routines/Routine.cs index ef6d6627d..984b0d769 100644 --- a/Assets/GothicVR/Scripts/Npc/Routines/Routine.cs +++ b/Assets/GothicVR/Scripts/Npc/Routines/Routine.cs @@ -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]; + } } }