Null Reference Error fix

for anyone facing this issue:

NullReferenceException: Object reference not set to an instance of an object
UnitActionSystemUI.CreateUnitActionButtons () (at Assets/Scripts/UnitActionSystemUI.cs:19)
UnitActionSystemUI.Start () (at Assets/Scripts/UnitActionSystemUI.cs:13)

just remove the selected lines in the below image.

& put them in awake, like this

1 Like

While I had them inside Awake() already, anyway (rule of thumb: if you do a GetComponent<>() for something on the same object, do it in Awake()), I would think the change to make it work in this case specifically would be to move these three lines before populating accessing the levelGrid, because the grid might try to access the Unit.

1 Like

In this case, the LevelGrid isn’t the culprit, it’s the UnitActionSystemUI, via the UnitActionSystem, as UnitActionSystem was changing the selected Unit, triggering the UnitActionSystemUI before the code now moved to Awake() was fired. Moving to Awake() remains the best solution.

1 Like

thanks!

Privacy & Terms