Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Property Drawers

Discussion in 'UI Toolkit' started by MartinIsla, Dec 9, 2018.

  1. etienne_unity

    etienne_unity

    Unity Technologies

    Joined:
    Aug 31, 2017
    Posts:
    102
    Since
    PropertyDrawer
    is not a type based on
    UnityEngine.Object
    , it doesn't support the "default references" feature. These are Object references stored in the script meta file, and only work for first-level properties of the host type.

    What you can do instead is use the
    AssetDatabase
    directly. You can use https://docs.unity3d.com/ScriptReference/AssetDatabase.LoadAssetAtPath.html to load a
    VisualTreeAsset
    , and use https://docs.unity3d.com/ScriptReference/AssetDatabase.GUIDToAssetPath.html to avoid relying on the asset path, and use its GUID instead (serialized in the asset .meta file).

    I hope this helps!
     
  2. steinbitglis

    steinbitglis

    Joined:
    Sep 22, 2011
    Posts:
    251
    This is Unity 2021.2.1, and we're approaching the 3 year anniversary of broken PropertyDrawer in UIElements, what happened?
    upload_2021-11-5_15-35-23.png
     
  3. MousePods

    MousePods

    Joined:
    Jul 19, 2012
    Posts:
    753
    Is this what you need? Added in 2022.1.0 Alpha 13

    • UI Toolkit: Added UI Toolkit implementation for property drawers.
     
  4. steinbitglis

    steinbitglis

    Joined:
    Sep 22, 2011
    Posts:
    251
    That's good news at least
     
    MousePods likes this.
  5. AdamBebko

    AdamBebko

    Joined:
    Apr 8, 2016
    Posts:
    161
    Sounds like a useful workaround but not very maintainable. Are there any plans to reference visualassettrees more easily and “unity like” so we can design our property drawers in UI builder?
     
  6. PeppeJ2

    PeppeJ2

    Joined:
    May 13, 2014
    Posts:
    41
    I made a Property Drawer like so:
    Code (CSharp):
    1.     [CustomPropertyDrawer(typeof(PIDValue))]
    2.     public class PIDValuePropertyDrawer : PropertyDrawer
    3.     {
    4.         public override VisualElement CreatePropertyGUI(SerializedProperty property)
    5.         {
    6.             var uiRootAsset = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>("Assets/PID/Editor/PIDValueUI.uxml");
    7.      
    8.             var uiRoot = uiRootAsset.CloneTree();
    9.  
    10.             uiRoot.BindProperty(property);
    11.      
    12.             return uiRoot;
    13.         }
    14.     }
    Then I made an editor wrapper like @pirho_luke suggested:
    Code (CSharp):
    1.     [CustomEditor(typeof(MonoBehaviour), true)]
    2.     public class ImguiToToolkitWrapper: UnityEditor.Editor
    3.     {
    4.         public override VisualElement CreateInspectorGUI()
    5.         {
    6.             var root = new VisualElement();
    7.        
    8.             var prop = serializedObject.GetIterator();
    9.             if (prop.NextVisible(true))
    10.             {
    11.                 do
    12.                 {
    13.                     var field = new PropertyField(prop);
    14.  
    15.                     if (prop.name == "m_Script")
    16.                     {
    17.                         field.SetEnabled(false);
    18.                     }
    19.                
    20.                     root.Add(field);
    21.                 }
    22.                 while (prop.NextVisible(false));
    23.             }
    24.  
    25.             return root;
    26.         }
    27.     }
    So far I've not really run in to any issues. This should also be really easy to code-gen (make a template file and just replace the type names) should the boilerplate be too much.
     
    Last edited: Nov 13, 2021
    Frolky likes this.
  7. steinbitglis

    steinbitglis

    Joined:
    Sep 22, 2011
    Posts:
    251
    @PeppeJ2 you can just create this editor as a base class, and inherit from it every time you have a new type that needs the property drawer. Then it's just 2 lines of code, not a full template.

    But I still wasn't happy, because the point of a property drawer is to avoid having to make any editors that serve no other purpose than contain the properties.

    With 2022.1.0 Alpha 13 though, property drawers are still working as advertised again (if the rumors are true) :).
     
    PeppeJ2 likes this.
  8. Ruchir

    Ruchir

    Joined:
    May 26, 2015
    Posts:
    927
    Looks like this is still a problem and it's really inconvenient right now. I'm using 2022.1.a12 :(
     
    progdruid likes this.
  9. steinbitglis

    steinbitglis

    Joined:
    Sep 22, 2011
    Posts:
    251
    Since the fix, now mentioned multiple times in this thread, is in 2022.1.0 Alpha 13, it makes sense that the fix was not there in alpha 12.
     
    MousePods and Ruchir like this.
  10. Stacklucker

    Stacklucker

    Joined:
    Jan 23, 2015
    Posts:
    82
    I hope this "fix" will soon see its light in 2021, otherwise what a joke this is. Are we supposed to upgrade to 2022, which won't see an LTS version for another 1.5 YEARS in order for property drawers to work properly? Hasn't UIElements been in development for years?
     
  11. watsonsong

    watsonsong

    Joined:
    May 13, 2015
    Posts:
    555
    Hi, in this method "CreatePropertyGUI" is no way to access the custom label and tooltips in PropertyField.
    I post this question from: https://forum.unity.com/threads/how...rawer-createpropertygui.1184404/#post-7603942
     
  12. watsonsong

    watsonsong

    Joined:
    May 13, 2015
    Posts:
    555
    Hi, is there really no one met this problem?

    The label of a PropertyField can not pass to a custom PropertyDrawer.CreatePropertyGUI. But it has duty to create a label. So the only way to get label is from the SerailizeProperty, but not the PropertyField specified label.
    This behaviour is different from the OnGUI version and not correct.
     
  13. steinbitglis

    steinbitglis

    Joined:
    Sep 22, 2011
    Posts:
    251
    CreatePropertyGUI and OnGUI are alternatives. The first one works with UI Toolkit, the second one works with IMGUI. I don't see why you would want both, or why you would pass data between them. In UI Toolkit, the label is a child VisualElement of the PropertyField. The label VisualElement has a text property.

    Correct me if I misunderstood.
     
  14. watsonsong

    watsonsong

    Joined:
    May 13, 2015
    Posts:
    555
    I am not need both, it want to use the 'CreatePropertyGUI' to implement the same ability as the 'OnGUI' could be.
    For example, when I use ‘OnGUI’ I can write this code to specify a custom label:
    Code (CSharp):
    1.  
    2. EditorGUILayout.PropertyField(prop, new GUIContent("My Custom Label"));
    3.  
    4. class MyCustomPropDrawer : PropertyDrawer
    5. {
    6.     public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    7.     {
    8.         EditorGUI.Label(position, label); // label = "My Custom Label"
    9.     }
    10. }
    11.  
    But when I use the UIElements, there is no way to get the label:
    Code (CSharp):
    1.  
    2. <?xml version="1.0" encoding="utf-8"?>
    3. <engine:UXML>
    4.     <editor:PropertyField label="My Custom Label" binding-path="prop"/>
    5. </engine:UXML>
    6.  
    7. class MyCustomPropDrawer : PropertyDrawer
    8. {
    9.     public override VisualElement CreatePropertyGUI(SerializedProperty property)
    10.     {
    11.         var root = new Label();
    12.         root.text = property.displayName; // This is not "My Custom Label"
    13.         return root;
    14.     }
    15. }
    16.  
    There is no way to get the label specify in the uxml(As it can specified in EditorGUI.PropertyField)。
     
  15. steinbitglis

    steinbitglis

    Joined:
    Sep 22, 2011
    Posts:
    251
    SerializedProperty is not a UI Toolkit thing, it's unitys internal serialization.

    To get a hold of the label you have there you need to load it from file, like this:

    Code (CSharp):
    1. var visualTree = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>("Assets/RW/Editor/PresetWindow.uxml");
    2. VisualElement labelFromUXML = visualTree.CloneTree();
    Then you can return that.

    Or you can build it from code, like in this example: https://docs.unity3d.com/ScriptReference/PropertyDrawer.html
     
  16. watsonsong

    watsonsong

    Joined:
    May 13, 2015
    Posts:
    555
    I means if I use the PropertyField widget in UIElements, to display a SerializedProperty with custom PropertyDrawer. If the PropertyDrawer implement the CreatePropertyGUI, it have no way to get the correct label provide from PropertyField.

    What I want is the label specified in the UXML, but not the only, specified UXML. I want to get the label specify in any PropertyField.

    For example I have a class name 'A' with a PropertyDrawer. And I use A in more than one place, give it custom name in custom editor(not the variable name from SerializedProperty). I need a way to get the label, just as the OnGUI last parameter.

    Just like the 'label' parameter in this method:
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label);

    I need the 'label' parameter in this method:
    public override VisualElement CreatePropertyGUI(SerializedProperty property, GUIContent label);
     
    Last edited: Mar 24, 2022
  17. steinbitglis

    steinbitglis

    Joined:
    Sep 22, 2011
    Posts:
    251
    Aha, now I've understood your problem, at least :)

    Before the UI Toolkit propertydrawers became default, this is what I used as editor base class, to enable UIElements property drawers:

    Code (CSharp):
    1. using UnityEngine.UIElements;
    2. using UnityEditor.UIElements;
    3.  
    4. public class UIElements_DefaultEditor : UnityEditor.Editor {
    5.  
    6.     public override VisualElement CreateInspectorGUI() {
    7.         var container = new VisualElement();
    8.  
    9.         var iterator = serializedObject.GetIterator();
    10.         if (iterator.NextVisible(true)) {
    11.             do {
    12.                 var propertyField = new PropertyField(iterator.Copy()) { name = "PropertyField:" + iterator.propertyPath };
    13.  
    14.                 if (iterator.propertyPath == "m_Script" && serializedObject.targetObject != null)
    15.                     propertyField.SetEnabled(value: false);
    16.  
    17.                 container.Add(propertyField);
    18.             }
    19.             while (iterator.NextVisible(false));
    20.         }
    21.         return container;
    22.     }
    23. }
    In this case it does not seem like setting propertyField.label will create a label for me, even when I set it from the editor code. I don't know what's going on with that.
     
  18. watsonsong

    watsonsong

    Joined:
    May 13, 2015
    Posts:
    555
    In the source code it try to invoke 'CreatePropertyGUI' first:
    Code (CSharp):
    1.  
    2. customPropertyGUI = handler.propertyDrawer.CreatePropertyGUI(m_SerializedProperty);
    3. if (customPropertyGUI == null) {
    4.     customPropertyGUI = CreatePropertyIMGUIContainer();
    5. } else {
    6.     RegisterPropertyChangesOnCustomDrawerElement(customPropertyGUI);
    7. }
    8.  
    In the 'CreatePropertyIMGUIContainer', it pass the label into it, but the label is not pass to 'CreatePropertyGUI':
    Code (CSharp):
    1.  
    2. private VisualElement CreatePropertyIMGUIContainer() {
    3.     GUIContent customLabel = string.IsNullOrEmpty(label) ? null : new GUIContent(label);
    4.     return new IMGUIContainer(() => {
    5.         EditorGUILayout.PropertyField(serializedProperty, new GUIContent(label), true);
    6.     });
    7.  
    So I think the unity need change it API to pass the label into 'CreatePropertyGUI'.
     
  19. felipemullen

    felipemullen

    Joined:
    Mar 4, 2017
    Posts:
    44
    Read through the thread, seeing the custom editor workaround, seeing a mention of a fix having been implemented in 2022.1.0 Alpha 13, but still seeing the same issue in 2022.1.0b14
    upload_2022-4-5_6-38-21.png

    To my understanding, b14 should contain fixes from a13 correct?
     
  20. felipemullen

    felipemullen

    Joined:
    Mar 4, 2017
    Posts:
    44
    Well. One way or another, I've updated to 2022.2.0a9, the bleeding edge.
    `CreatePropertyGUI` now works as expected, without the need of a custom editor.

    Who needs API stability when they're just an hobbyist indie dev?
     
    PeppeJ2 and RunninglVlan like this.
  21. watsonsong

    watsonsong

    Joined:
    May 13, 2015
    Posts:
    555
    I remember the UIElements can embed an OnGUI. But OnGUI can not embed UIElements. If the PropertyDrawer is used inside another OnGUI editor, with only `CreatePropertyGUI` but no 'OnGUI', it looks like this.
     
  22. MikeDPad

    MikeDPad

    Joined:
    May 23, 2013
    Posts:
    3
    I appreciate all the useful input from everyone on this thread. It has been some time since I used Unity and wanted to reacquaint myself with the new tooling provided in that timespan. Learned quite a bit about some of the pitfalls of using the UI Toolkit API... after hearing about this years ago!

    I wanted to create some customized PropertyDrawers and Editors only to find that the new UI Toolkit, confusingly in the UnityEngine.UIElements and UnityEditor.UIElements namespaces, only work properly in the latest alphas of 2022.2.x + ... I was able to get them working after reading this thread.

    A simple, serializable class...
    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. [System.Serializable]
    4. public class FollowPoint
    5. {
    6.     public string name;
    7.     public Vector3 offset = Vector3.zero;
    8.     public Vector3 lookAt = Vector3.zero;
    9. }
    The property drawer for said class...
    Code (CSharp):
    1. using UnityEditor;
    2. using UnityEngine.UIElements;
    3.  
    4. [CustomPropertyDrawer(typeof(FollowPoint))]
    5. public class FollowPointDrawer : PropertyDrawer
    6. {
    7.     public override VisualElement CreatePropertyGUI(SerializedProperty property)
    8.     {
    9.         VisualTreeAsset vta = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>("Assets/Resources/UI/XML/FollowPointDrawer.uxml");
    10.         VisualElement ve = vta.CloneTree();
    11.         return ve;
    12.     }
    13. }
    14.  
    I was getting an error using the CloneTree method example provided on the Load UXML from C# scripts page. An argument of null is ambiguous between the other overloaded methods, so I didn't pass any parameters.

    Is this minimal example correct usage?
     
    marcospgp likes this.
  23. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,194
    I think you'd want to:

    Code (csharp):
    1. VisualElement ve  = vta.CloneTree(property.propertyPath);
    Otherwise you'd have to go through the sub properties (name, offset, lookAt) one by one and bind them by hand.
     
  24. AdamBebko

    AdamBebko

    Joined:
    Apr 8, 2016
    Posts:
    161
    Is there a better way to reference the visual tree for a property drawer yet? rather than a hard-coded path?
     
    dsfgddsfgdsgd likes this.
  25. marcospgp

    marcospgp

    Joined:
    Jun 11, 2018
    Posts:
    162
    Property drawer with UI Toolkit following instructions in documentation is still not working for me in 2022.1.16f1, only showing "No GUI Implemented". Are the docs ahead of the editor?
     
  26. uDamian

    uDamian

    Unity Technologies

    Joined:
    Dec 11, 2017
    Posts:
    1,203
    This should start working in 2022.2+. In 2022.2, we've switched default inspector generation to UI Toolkit. This means, finally, UI Toolkit-exclusive custom PropertyDrawers will now work everywhere.
     
  27. AlexFCL

    AlexFCL

    Joined:
    Mar 27, 2013
    Posts:
    17
    Hi @uDamian , any chance that UI Toolkit custom propertyDrawers for default inspector will be supported in Unity3D 2021?
     
    Last edited: Nov 14, 2022
  28. uDamian

    uDamian

    Unity Technologies

    Joined:
    Dec 11, 2017
    Posts:
    1,203
    Unfortunately, this is not something we can backport to 2021 LTS. It's a non-trivial change.
     
  29. Kekito

    Kekito

    Joined:
    Nov 24, 2016
    Posts:
    14
    How would that base class look? Couldnt make it work either way
     
  30. gilbertoalexsantos

    gilbertoalexsantos

    Joined:
    Nov 5, 2016
    Posts:
    3
    It is showing "No GUI Implemented" for me in 2022.2.1f1 =/
     
  31. watsonsong

    watsonsong

    Joined:
    May 13, 2015
    Posts:
    555
    Maybe it because the UIElements implemented PropertyDrawer can not invoked by OnGUI. You need implement both the UIElements and OnGUI implement for a PropertyDrawer?
     
  32. gilbertoalexsantos

    gilbertoalexsantos

    Joined:
    Nov 5, 2016
    Posts:
    3
    idk...

    I have just created an empty project using Unity 2022.2.1f1, and the Inspector is being drawn using IMGUIContainers.

    According to the release notes, it should use UIToolkit elements (Label/Box/etc).
     
  33. gilbertoalexsantos

    gilbertoalexsantos

    Joined:
    Nov 5, 2016
    Posts:
    3
    I just found the issue:

    I had this somewhere in my codebase:
    Code (CSharp):
    1. // Required for the fetching of a default editor on MonoBehaviour objects.
    2.     [CanEditMultipleObjects]
    3.     [CustomEditor(typeof(MonoBehaviour), true)]
    4.     public class MonoBehaviourEditor : UnityEditor.Editor { }
    5.  
    6.     // Required for the fetching of a default editor on ScriptableObject objects.
    7.     [CanEditMultipleObjects]
    8.     [CustomEditor(typeof(ScriptableObject), true)]
    9.     public class ScriptableObjectEditor : UnityEditor.Editor { }
    And it was forcing my drawer to use OnGUI. Not sure why though.
     
  34. Aldeminor

    Aldeminor

    Joined:
    May 3, 2014
    Posts:
    18
    Code (CSharp):
    1. [CustomEditor(typeof(UnityEngine.Object))]
    2. public class DefaultUIElementsEditor : Editor
    3. {
    4.     private const string script_property_name = "m_Script";
    5.     public override VisualElement CreateInspectorGUI()
    6.     {
    7.         var root = new VisualElement();
    8.         var iterator = serializedObject.GetIterator();
    9.         if (iterator.NextVisible(true))
    10.         {
    11.             do
    12.             {
    13.                 VisualElement propertyField;
    14.                 if (iterator.propertyPath.Equals(script_property_name) && serializedObject.targetObject)
    15.                 {
    16.                     propertyField = CommonUIElements.CreateDisabledClickableObjectField(
    17.                         iterator.Copy(),
    18.                         obj=> AssetDatabase.OpenAsset(obj),
    19.                         out _);
    20.                 }
    21.                 else propertyField = new PropertyField(iterator.Copy()) { name = $"PropertyField: {iterator.propertyPath}" };
    22.                 root.Add(propertyField);
    23.             }
    24.             while (iterator.NextVisible(false));
    25.         }
    26.         return root;
    27.     }
    28. }
    29. ... (following is in another static class for shorthand)
    30. public static VisualElement CreateDisabledClickableObjectField(
    31.     SerializedProperty objectReferenceProperty,
    32.     Action<Object> doubleClickAction,
    33.     out ObjectField underlyingField)
    34. {
    35.  
    36.     var objectField = new ObjectField(objectReferenceProperty.displayName)
    37.     {
    38.         value = objectReferenceProperty.objectReferenceValue
    39.     };
    40.     objectField.SetEnabled(false);
    41.     var clickableContainer = new VisualElement();
    42.     clickableContainer.Add(objectField);
    43.     clickableContainer.RegisterCallback<MouseDownEvent>(evt =>
    44.     {
    45.         if (!objectField.value)
    46.             return;
    47.         EditorGUIUtility.PingObject(objectField.value);
    48.         if (evt.clickCount == 2)
    49.             doubleClickAction?.Invoke(objectField.value);
    50.          
    51.     } );
    52.     underlyingField = objectField;
    53.     return clickableContainer;
    54. }
    I've slightly improved your awesome Default UIElements Editor: added an actually functional Script field (clickable), also there is no need to have 'fallback = true' parameter because it sometimes breaks the inspector.
     
  35. Kazko

    Kazko

    Joined:
    Apr 2, 2014
    Posts:
    82
    This is the topic of my days. Not specifically in regards to drawing default properties, but more about IMGUI vs UIT support and performance across Unity versions. TLDR: I want to create a tool with a wide support across versions to reach as many users as possible. Therefore I have created it in IMGUI as a custom property drawer in 2020 LTS. However because I need the inspector responsive, I am using Repaint, which generates GC Allocations. The GCs are ok in 2020 LTS (around 24 kb) but each major Unity release increases this significantly probably due to the transition to UITK - in 2022 it's 4x and in 2023 beta it's almost 10x higher than 2020 LTS.
    Full story: https://forum.unity.com/threads/inspector-repaint-and-gc-allocations-in-unity-versions.1402837/

    So naturally I wanted to remake the tool in UITK, but struggling with wide editor support. I enabled support for UIT alternative for Unity versions older than 2022.2 by using code in this thread, and it stops working correctly at 2020 LTS where the behavior is a bit different. So for older versions I wanted to retain the IMGUI implementation. Could you please answer or give any insight for the following issues?

    1) Is this workaround a bad practice for a public editor tool?
    Code (CSharp):
    1. [CustomEditor(typeof(UnityEngine.Object))]
    2. public class DefaultUIElementsEditor : Editor
    3. {
    It seems that this affects all drawers and can have undesirable impact or conflicts in people's projects.

    2) I have enclosed the workaround in
    Code (CSharp):
    1. #if UNITY_2021_3_OR_NEWER
    so that in older versions the default IMGUI alternative is drawn. Is there a better way of making the alternatives coexist across editor versions?

    3) Or perhaps, should I even be worried about GC when constantly repainting the inspector?

    Thanks for any insights!
     
    Ruchir likes this.
  36. uDamian

    uDamian

    Unity Technologies

    Joined:
    Dec 11, 2017
    Posts:
    1,203
    This does indeed warrant some questions and worries. What are you trying to do by overriding ALL custom Editors? I'm not even sure what this does actually, because it seems like it would break a lot of inspectors if it worked.

    You could try to implement both IMGUI and UITK. You can do this in the same Editor, just define both OnInspectorGUI() and CreateInspectorGUI(). UITK will always be picked if in a UITK context (like the Inspector itself). But for older version, the IMGUI option will be picked, and for very old versions you can easily if-def the UITK side. Same goes for PropertyFields. Starting in 2022.2+, the default Inspectors now use UITK natively so UITK PropertyDrawers will work in default inspectors.

    If you're specifically talking about the rise in GC in 2023.1, this is a bug, and a fix should land soon. It won't return to the same levels but it should improve significantly. The reason there was this increase in 2023.1 is because we switched the text backend of IMGUI to TextCore (the tech taken from TextMeshPro and used by UI Toolkit). This backend is made for retained more UIs, and it's pure C# (unlike the legacy TextNative backend of IMGUI previously). But now that all UI frameworks are on the same text backend, we can improve performance and stability across all three at the same time.
     
    Kazko likes this.
  37. Kazko

    Kazko

    Joined:
    Apr 2, 2014
    Posts:
    82
    This is a solution suggested in this thread. I am not using it currently because my use case is a public tool.
     
  38. Kazko

    Kazko

    Joined:
    Apr 2, 2014
    Posts:
    82
    That's good to know! Thanks. However the question stands - in general, causing constant 25 kB GC by my inspector tool is ok? In the meantime I optimized it a lot and I'm only repainting when dragging things, but I want to keep a fully responsive mode as an option (25 - 50 kB GC depending on Unity version).
     
  39. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,194
    This is a common workflow. A good example is Odin, which does this. We have also done it for our own games earlier, though we haven't had the need in the last game, so I'm not 100% clear on the details anymore.

    Usually what you do is to define your own inspector for everything, and then you use reflection or some other means to figure out what inspector is defined for the thing, and use that if it exists, so you don't override the BoxCollider inspector.

    The reason to override all custom inspectors is twofold:
    - The ability to make a custom editor that targets builtin types that doesn't have a type you can target - either because the type is internal, or because it's not got a proper type. The primary example is making custom editors for folders. That can be useful to set up metadata about how the stuff in the folder should be treated by other systems (like importers), and in some cases it's useful to have a custom view for the data inside the folder.

    - Support for more kinds of attributes. This is what Odin does, and it's relevant for other workflows. Unity has a very attractive way of defining custom editors through the use of attributes instead of creating your own custom editor, but that workflow is very limited - PropertyFields for attributes has this annoying thing where it targets elements of an array, having the different attributes know about and react to each other is a pain, but totally necessary if say one changes how things are drawn and another conditionally hides it.
     
    SisusCo and Kazko like this.
  40. Kazko

    Kazko

    Joined:
    Apr 2, 2014
    Posts:
    82
    For a private project it sounds good, and Odin is about overriding all inspectors in some way or another. The original question is whether this is a good practice for a use case where a inspector tool with a custom drawer for public use could end up overriding all other drawers in people's projects, possibly creating issues and conflicts. As you seem to have a lot of experience with this, what's your take on this? Thank you!
     
  41. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,194
    Right, I was responding to Damian just to make sure we're clear on what people do. It's always worrying to see somebody from Unity going "does that even work?" when it's something we do a lot. It's especially worrying to see someone from Unity going "does that even work" when they're on the team responsible for that thing continuing to work.

    But, yeah, to answer your question, overriding all editors is a pretty heavy thing to do! You probably don't want to do it unless there's a very clear benefit to the user. One thing to note is that you're probably making yourself incompatible with Odin, which is a very common tool - unless you're doing some kind of #if ODIN_INSTALLED thing. You're also adding overhead to people who want to both use your attributes and have custom inspectors - they have to inherit from a specific thing (which isn't the end of the world, but it's friction).

    So I would avoid it if I could! But if you're making a very large set of tools (aka. you're an Odin competitor, or have something as intrusive), it could be worthwhile.
     
  42. Kazko

    Kazko

    Joined:
    Apr 2, 2014
    Posts:
    82
    Yeah, that was my feeling too when I saw this suggestion. Wouldn't hesitate to do it this way in my own project, but for the tool, I actually decided not to do UITK version at all (for now) and rather implement it in a later update. Anyway thanks for the insights!
     
  43. uDamian

    uDamian

    Unity Technologies

    Joined:
    Dec 11, 2017
    Posts:
    1,203
    I would focus on overall performance, instead of trying really hard to get to zero GC - especially in an IMGUI-based inspector. If your inspector is responsive enough and your not outright leaking the GC allocs, should be ok.
     
    Kazko likes this.
  44. uDamian

    uDamian

    Unity Technologies

    Joined:
    Dec 11, 2017
    Posts:
    1,203
    I'm aware of what Odin is doing, but as you say yourself in the second message, this is _not_ a common thing to do - to override ALL inspectors. You rely on a fallback system that was never designed to handle a lot of options for custom inspector of a single type.

    But ya, it's true that I we don't internally override ALL inspectors very often. So it's not something top of mind for me and I wouldn't recommend this path for even most tools developers - because of all the reasons you gave - but most of all because it will 100% conflict with others trying to do the same thing. It's there and indeed very powerful, for tools like Odin, but should not be a first choice.