- Home /
DrawDefaultEditor causing field to be serialized multiple times?
The same field name is serialized multiple times in the class or it's parent class. This is not supported: Base(MonoBehaviour) m_Name
UnityEditor.Editor:DrawDefaultInspector()
GridInspector:OnInspectorGUI() (at Assets/Editor/GridInspector.cs:12)
UnityEditor.DockArea:OnGUI()
I don't get it. Here's an example grid class below:
[Serializable]
public class Grid : MonoBehaviour {
[SerializeField]
private int m_Width;
[SerializeField]
private int m_Length;
[SerializeField]
private float m_TileSize;
[SerializeField]
private string m_Name;
[SerializeField]
private int[,] m_GridTile;
public Grid ()
{
m_Name = "";
}
void OnGUI ()
{
m_Width = EditorGUILayout.IntField("Width", m_Width);
m_Length = EditorGUILayout.IntField("Length", m_Length);
m_TileSize = EditorGUILayout.FloatField("Tile Size", m_TileSize);
//m_Name = EditorGUILayout.TextField("Name", m_Name);
}
}
Here's my inspector code
[CustomEditor(typeof(Grid))]
public class GridInspector : Editor
{
[SerializeField]
private Grid grid;
public override void OnInspectorGUI()
{
DrawDefaultInspector();
grid = (Grid)target;
if (GUILayout.Button("Regenerate"))
{
//grid.MakeGrid();
}
}
}
I would understand if I'm trying to re-declare the serialization but I'm not.
FUN FACT
If I change m_Name to m_Namee this works perfectly... is m_Name a hidden variable somewhere in the base class?
Answer by ZhangTianHou · Apr 01, 2017 at 07:18 AM
yes you must use different name of field in base class and sub class
if base class has public variable,you can also see this variable in the inspector after the sub class serialize. so when you sub and base classes both have same name of variables,the unity doesnt know which one need serialize
Your answer
Follow this Question
Related Questions
Unable to draw propertyfield in inspector for some classes, findProperty returns null. 0 Answers
Assign min / max values to range in inspector. 3 Answers
Serialize Custom Abstract Class (No-MonoBehaviour / No-ScriptableObject) 1 Answer
Serialization of inherited classes, could this work? 0 Answers
CustomScroll inherited from RectScroll, executing in edit mode 0 Answers