Problem is not reproducible or outdated
Change serialized array size
Hi, i have a problem with my serializable class. The array "usable" was a 13 elements array in the past, now I've changed its size to 14. But i'm unable to play the game, because in the saved data the array has the size of 13 elements. If I delete the player data on my PC it works, but in android I can't do that on all the users phones! Please help me.
Answer by Adam-Mechtley · Dec 19, 2016 at 08:18 AM
If you are just populating this field at run-time, then I would mark it with System.NonSerializedAttribute or similar. If you do in fact have actual data saved in this field in assets, you could copy and resize this field in OnEnable () or ISerializationCallbackReceiver.OnAfterDeserialize (), though the better option would be to write some kind of editor script that updates all of your prefabs offline.
Hi Adam! Thanks for your respond. I use the array "usable" to know witch characters have the player unlocked, I load and save data on it. $$anonymous$$y game's users have already a file on their phones with this structure, and now I want to change this array size. Unity has a script that lets you change a serialized field's name, but they are any help to change an array size :(
I think that if I change the array size in OnEnable(), maybe the problem stills there, because the user has this array on the persistance data file with 13 elements.
I don't know how you're storing this persistent data on the user's device, but the idea here is you are just checking its length when you deserialize. If it is too short, you increase the length of the deserialized array and re-serialize and save the data on the device as needed.