NullReferenceException: Object reference not set to an instance of an object
ActionButtonUI.SetBaseAction (BaseAction baseAction) (at Assets/Scripts/ActionButtonUI.cs:15)
UnitActionSystemUI.CreateUnitActionButtons () (at Assets/Scripts/UnitActionSystemUI.cs:30)
UnitActionSystemUI.Start () (at Assets/Scripts/UnitActionSystemUI.cs:15)
I’m getting a NRE from the anonymous function we set up in the last lecture but the error only popped up after the refactoring of the code in this lecture. I went through and triple checked my code against the lecture and even copied and pasted all of the scripts we’ve changed in the last 2 lectures to still get this error.
While trying to debug, the actions are in the container but when being instantiated they aren’t being created. I added debug logs to show which action was being created but the log doesn’t show in the console.
foreach (BaseAction baseAction in selectedUnit.GetBaseActionArray()){
Transform actionButtonTransform = Instantiate(actionButtonPrefab, actionButtonContainerTransform);
ActionButtonUI actionButtonUI = actionButtonTransform.GetComponent<ActionButtonUI>();
actionButtonUI.SetBaseAction(baseAction);
Debug.Log("BaseAction " + baseAction);
}
The NRE error is the only error I’m getting