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?