- Home /
Renaming Serialized Classes
I've followed the format in this post and extend it to classes: http://docs.unity3d.com/460/Documentation/ScriptReference/Serialization.FormerlySerializedAsAttribute.html
It's mentioned in the blog comments that this technique should work for classes as well, though I've failed to get the project compiling after such a rename.
I'm trying to rename a mono behaviour class from 'MUIWidget' to MIUWidgetAgent'.
This is a snippet from the code I used. Any suggestions?
using UnityEngine;
using UnityEngine.Serialization;
using System.Collections;
[RequireComponent(typeof(Agent))]
[System.Serializable]
[FormerlySerializedAs("MUIWidgetAgent")]
public class MUIWidgetAgent : MonoBehaviour
{
.......
Answer by MetzT · Jul 08, 2019 at 04:10 PM
"FormerlySerializedAs" attribute unfortunately only works for fields. As actually mentioned in the documentation. https://docs.unity3d.com/ScriptReference/Serialization.FormerlySerializedAsAttribute.html "Use this attribute to rename a field without losing its serialized value."
Unity does not provide any alternatives however, there are plugins like Odin which do.
Your answer
Follow this Question
Related Questions
Property drawer stops variables from being read 0 Answers
Best practice custom class with GameObject 0 Answers
custom class serialization problem 1 Answer
Can a Monobehaviour extend a class? 1 Answer