From 5be2cb43ff231a63df5e1f8b0cb82ee12b387089 Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Mon, 8 Aug 2022 16:39:11 -0400 Subject: [PATCH] Fix NRE in DebugPropPlacer.cs --- .../Utility/DebugUtilities/DebugPropPlacer.cs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/NewHorizons/Utility/DebugUtilities/DebugPropPlacer.cs b/NewHorizons/Utility/DebugUtilities/DebugPropPlacer.cs index aa656e5e..9e6f25d4 100644 --- a/NewHorizons/Utility/DebugUtilities/DebugPropPlacer.cs +++ b/NewHorizons/Utility/DebugUtilities/DebugPropPlacer.cs @@ -93,9 +93,10 @@ namespace NewHorizons.Utility.DebugUtilities // TODO: implement sectors // if this hits a sector, store that sector and add a config file option for it - if (!data.hitBodyGameObject.name.EndsWith("_Body")) + if (data.hitBodyGameObject == null) { - Logger.LogWarning("Cannot place object on non-body object: " + data.hitBodyGameObject.name); + Logger.LogError($"Failed to place object {currentObject} on nothing."); + return; } try @@ -106,6 +107,12 @@ namespace NewHorizons.Utility.DebugUtilities } var planetGO = data.hitBodyGameObject; + + if (!planetGO.name.EndsWith("_Body")) + { + Logger.LogWarning("Cannot place object on non-body object: " + data.hitBodyGameObject.name); + } + var sector = planetGO.GetComponentInChildren(); var prefab = SearchUtilities.Find(currentObject); var detailInfo = new PropModule.DetailInfo() @@ -114,7 +121,9 @@ namespace NewHorizons.Utility.DebugUtilities rotation = data.norm, }; var prop = DetailBuilder.MakeDetail(planetGO, sector, prefab, detailInfo); - var propData = RegisterProp_WithReturn(data.hitBodyGameObject.GetComponent(), prop); + + var body = data.hitBodyGameObject.GetComponent(); + if (body != null) RegisterProp(body, prop); SetGameObjectRotation(prop, data, playerAbsolutePosition); }