I have a customized inspector window via an editor script. I have a little [ + ] and [ - ] button to add items to a List. The problem is when I press the [ + ] button to add a new item to the list, it throws a few NullReferenceException’s at me in the error log before showing the new list item in the inspector. I think what’s happening is when I add a new item to the List, it hasn’t quite initialized by the time the Editor Script is trying to run through itself again, so it logs an error once or twice before it’s able to display the new item.
But how can I prevent the errors? I can’t say… if ( listArray[num].item != null )
because then it just throws a NullReferenceException as the item doesn’t exist yet! However the listArray.Count is updating early so my code still believes there is an item there when there isn’t yet…