Array only initialized when serializable[SOLVED]

Please use code tags .

If you use Unity’s inspector to look at a variable containing a serializable class, and the object is null, Unity will replace it with a new (non-null) instance instead. This only happens in the editor when you are actually looking at that object and is a side-effect of the fact that the JSON serializer Unity uses for this doesn’t allow nulls.

If you were also using the inspector to set the initial value of your variable, then this probably wouldn’t matter. But since you are overwriting the default values in Awake (creating a new array to replace the serialized one) you get all the normal C# rules for data, which means your array starts out filled with null.

If you don’t want nulls, you can easily add a loop in your Awake function to assign new objects to each slot in the array.

If the problem is that you DO want nulls, and Unity is replacing them, then you’re just going to have to stop letting Unity serialize the array, sorry. That means it won’t be visible in the inspector, so if you want to see the data at runtime you’ll need to figure out another way to do that.