- Home /
Keep values in inspector while changing variable name
Hi everybody.
I have a public GameObject[] array named myArray.
In the inspector, I filled it with many GameObjects.
For some reason, I want to change the array's name for a better one, like myGameObjects. But if I do so, I will loose all the values I had put in the inspector. Any way to avoid this ?
Answer by Adam-Mechtley · May 08, 2018 at 01:16 PM
You can use the FormerlySerializedAsAttribute to rename a field and retain your saved data. The next time the component/scriptable object is deserialized it will be automatically upgraded, and the next time you save it to disk it will be serialized with the new name.
Great, seems to be exactly what I was looking for. I must say that the subtleties of serialization are still a bit obscure to me. Thanx a lot.
If it helps, I recommend the Script Serialization section of the docs
Yes, I think reading this will definitely help. I put it on my (already long) to-learn list.
Thanx again.
Answer by anthot4 · May 08, 2018 at 11:57 AM
No there isn't as far as I know. Just write down all the gameobjects you had in the array before you rename it.
I was hoping there would be some kind of dynamic link. Thanks anyway for the answer.
Sorry for the down vote, @anthot4, it's purely accidental. I keep on trying to upvote your answer, but it keeps displaying negative values. The best I can do is keep it to zero. $$anonymous$$y apologies.
Thanx for your comprehension. I was feeling so sorry when, trying to upvote, I saw the values going down to -2, -3... What the hell ?! Don't know if it's a website bug. $$anonymous$$aybe I should consider getting rid of Safari once for all.
Your answer
Follow this Question
Related Questions
How to serialize an array of classes 1 Answer
Array on the Inspector 1 Answer
Array elements are empty in the inspector? 1 Answer
Custom inspector, a multidimensional array of enums 1 Answer
public fixed size array in inspector 4 Answers