- Home /
 
 
               Question by 
               Capricornum · Sep 08, 2020 at 08:49 PM · 
                serializationinstancecustom editorundo  
              
 
              Custom Editor serializing data in prefab instance.
Dear Community,
I have a tiny script called 'Tile':
 public class Tile : MonoBehaviour
 {
     [SerializeField]
     private Vector2Int _coordinate;
     public Vector2Int Coordinate 
     { get { return _coordinate; } set { _coordinate = value;} }
 }
 
               and a custom editor:
     [CustomEditor(typeof(Tile))]
     public class TileEditor : Editor
     {
         Tile tile;
         void OnEnable()
         {
             tile = (Tile)target;
         }
         public override void OnInspectorGUI()
         {
             Undo.RecordObject(tile, "Change on Tile");
             tile.Coordinate = 
             EditorGUILayout.Vector2IntField("Position", tile.Coordinate);
         }
     }
 
               It works fine. Even when I close Unity and open it again the data is serialized and everything seems to work.
In the Unity docs it says I should not do it like this when using instances of a prefab. Instead I should additionally be using 'PrefabUtility.RecordPrefabInstancePropertyModifications'.
Now I am scared to keep everything as it is, although it seems to be working for now. Since I don't grasp the concepts of these things but just use them I would be grateful for insight and good tips. Thank you.
               Comment
              
 
               
              Your answer