Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Restriction in custom editor with new prefab system

Discussion in 'Prefabs' started by astrokoala, Aug 20, 2018.

  1. astrokoala

    astrokoala

    Joined:
    Mar 23, 2016
    Posts:
    22
    If you write custom editor for your classes.

    Consider the following code
    Code (CSharp):
    1.  public class TestCustomEditor : MonoBehaviour
    2. {
    3.  
    4.      public float myFloat;
    5.      public Vector3 myVec3;
    6. }
    7.  
    8. [CustomEditor(typeof(TestCustomEditor))]
    9. public class TestCustomEditorEditor : Editor
    10. {
    11.      public override void OnInspectorGUI()
    12.      {
    13. //        return base.OnInspectorGUI();
    14.          EditorGUILayout.PropertyField(serializedObject.FindProperty("myFloat"));
    15.          serializedObject.FindProperty("myVec3").vector3Value = EditorGUILayout.Vector3Field("my vec", serializedObject.FindProperty("myVec3").vector3Value);
    16.          serializedObject.ApplyModifiedProperties();
    17.      }
    18. }
    if you make a prefab, then only the property with
    PropertyField
    method will show blue edge for override values
    override.PNG

    while for this case, the answer is really easy, just use PropertyField method if you want to fully work with new prefab system.

    however if you are used to writing your own custom editors for your classes, and specific property drawer methods are also useful in many cases, then it does not well with the new prefab system.

    likewise, Odin inspector and other editor based plugins also suffers this problem.

    Is there a guide to writing new prefab system compatible editors?
     
  2. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,892
    Adrien-TA and Havokki like this.