r/UnityHelp • u/UltraDuskknight • 1d ago
Static Class Isn't retaining Inspector references
I feel like I'm not understanding something about how static class instances work. every time i run this code it throws the null reference, but i had set the reference with the serialized field in the inspector. Is there something about the way static works or the way the awake function is called that is causing this issue? i feel like this sort of thing used to work.
Please Help
1
Upvotes


1
u/FrancisJCat 1d ago
Things to check
If all of that checks, then check when
SetTargetis called.Awakeshould run almost immediately after starting, but the order is not guaranteed. If another script is callingSetTargetfromAwake, and that other script executed first, theninstancewill be null