Array initialization and old prefabs

Let’s say I have a script with a single integer variable. Them I attach it to a Game Object, change the value to 10 and create a prefab from it.
The code and prefab content are:

public class NewBehaviourScript : MonoBehaviour
{
    public int i = -1;
}
(...)
--- !u!114 &114244378093798292
MonoBehaviour:
  m_ObjectHideFlags: 1
  m_PrefabParentObject: {fileID: 0}
  m_PrefabInternal: {fileID: 100100000}
  m_GameObject: {fileID: 1607964267855038}
  m_Enabled: 1
  m_EditorHideFlags: 0
  m_Script: {fileID: 11500000, guid: f36459e06c4890f4aaad1a388ad0b54c, type: 3}
  m_Name:
  m_EditorClassIdentifier:
  i: 10

But them I need to add an array to my script with a default content. The code now becomes:

public class NewBehaviourScript : MonoBehaviour
{
    public int i = -1;
    public int[] a = new int[] { 1, 2, 3, 4, 5 };
}

The behaviour in previous Unity versions was to add the array with the default values in the prefab and in all of its instances, but now (5.5.1) the value becomes an array with zero size.
If I add my script to a Game Object the default values show up as intended.

Is there a way to force the default values on the prefabs created before the code was changed?

You could write a Validate() function (which should be called after the prefabs are deserialized) - if it sees an empty array there, it sets the correct initialization values. (I suspect you’ll only need this Validate in there once - after it compiles it may deserialize all the prefabs, run the function, and then the new values will be in the prefabs for good.)

Disclaimer: I haven’t used Validate() in this way, and I might be wrong about my assumption on how it functions outside of the inspector. Worst case, after you insert the Validate function, you have to arrow-key through each prefab - once it shows in the inspector Validate will be called.

I think this approach would work. As far as I know, OnValidate is called for each prefab when you open the Editor.

But my project has multiple arrays like that, and some prefabs might have been correctly set with a zero sized array. I would have to know if the prefab file does or doesn’t have a parameter for the array.

I ended up downgrading Unity to 5.3.7, making a script to dirty all my prefabs, and then moving back to the current version. Not a lot of fun reimporting the project but it worked.

Thanks