NullReferenceException — practical investigation
NullReferenceException
Section titled “NullReferenceException”NullReferenceException tells you that code tried to use a reference that was null. It does not by itself prove which object was null or why.
Useful investigation order
Section titled “Useful investigation order”- Find the first relevant
NullReferenceExceptionand nearby stack/context lines. - Identify the first frame or method that belongs to your mod or the exact vanilla component you touched.
- Ask whether the object was expected to exist at that lifecycle moment.
- If this followed UI cloning, inspect copied
MonoBehaviour/EventTriggercomponents before adding broad null checks. - Reproduce with the smallest path possible and log the objects/fields immediately before the failing call.
UI warning
Section titled “UI warning”TerraForge reproduced a NullReferenceException by cloning an active vanilla UI cell whose copied behavior executed Awake() in the wrong context. The fix was not “add a null check everywhere”; it was to change the cloning lifecycle and remove unsafe copied behavior.