Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Feedback suggestion for editor

Discussion in 'General Discussion' started by steveh2112, Aug 3, 2023.

  1. steveh2112

    steveh2112

    Joined:
    Aug 30, 2015
    Posts:
    314
    i have 2 suggestions for the editor if anyone at unity is interested.
    1) have a duplicate option for components, less clicks than copy component and paste as new
    2) it would be nice to add a label to a component besides its component name. for example i have about 10 box colliders in my car and its hard to know which is which, would be great to label them hood, floor, trunk, seat, ldoor, rdoor, etc,
     
  2. MadeFromPolygons

    MadeFromPolygons

    Joined:
    Oct 5, 2013
    Posts:
    3,951
    you can do #1 really easily yourself using editor scripting. no need to bloat the engine just to save you 1 click

    #2 is also super trivial to do using editor scripting - again no need to bloat the engine just for your use case.
     
  3. John_Leorid

    John_Leorid

    Joined:
    Nov 5, 2012
    Posts:
    643
    Extending a custom inspector isn't that easy. With a mix of UI Toolkit and IMGUI it's somewhat easy but when you want to stick with one of the two, it's complicated. And I think the new custom inspectors are written in UI Toolkit (v2022 and up). Afaik they are internal, so you can't directly reference them, thus you can't derive from them to override anything.
     
  4. MadeFromPolygons

    MadeFromPolygons

    Joined:
    Oct 5, 2013
    Posts:
    3,951
    I would class extending a custom inspector as incredibly easy compared to many problems in game dev, but everyone has their own strengths and weaknesses. For me I find that sort of thing very trivial. Either way neither of these are likely to go into the engine for the reasons I just mentioned, whether others agree or not unfortunately
     
  5. DragonCoder

    DragonCoder

    Joined:
    Jul 3, 2015
    Posts:
    1,636
    Can you actually add a custom inspector for ALL scripts or modify the default? Since one wouldn't wanna create a new custom inspector for every single class.
     
  6. John_Leorid

    John_Leorid

    Joined:
    Nov 5, 2012
    Posts:
    643
    Yes, that's possible by creating a custom Inspector for the Type "MonoBehaviour" or even "Component" in your case. You can also create one for "UnityEngine.Object" I think.

    But of course you can only have one of them. So if you are using anything else that also relies on overriding the default inspector, it won't work. Things like Odin, EasyButtons, FoldoutAttribute, NaugthyAttributes and a few others rely on overriding the default inspector.
     
    angrypenguin and DragonCoder like this.
  7. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    20,740
    GPT-4 was able to create the component duplicator script with just two prompts (first one had an error).

    Code (csharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEditor;
    5.  
    6. public class ComponentDuplicator : Editor
    7. {
    8.     [MenuItem("CONTEXT/Component/Duplicate Component")]
    9.     public static void DuplicateComponent(MenuCommand command)
    10.     {
    11.         Component originalComponent = command.context as Component;
    12.  
    13.         if (originalComponent != null)
    14.         {
    15.             Undo.RecordObject(originalComponent.gameObject, "Duplicated Component");
    16.             CopyComponent(originalComponent);
    17.         }
    18.     }
    19.  
    20.     private static Component CopyComponent(Component original)
    21.     {
    22.         System.Type type = original.GetType();
    23.         Component copy = original.gameObject.AddComponent(type);
    24.         System.Reflection.FieldInfo[] fields = type.GetFields();
    25.  
    26.         foreach (System.Reflection.FieldInfo field in fields)
    27.         {
    28.             field.SetValue(copy, field.GetValue(original));
    29.         }
    30.  
    31.         return copy;
    32.     }
    33. }

    upload_2023-8-4_16-31-18.png
     
  8. John_Leorid

    John_Leorid

    Joined:
    Nov 5, 2012
    Posts:
    643
    Sure, I was just talking about #2, I should have made that clear. Because this doesn't need any override of the existing inspector, it's just a Menu Entry. Therefore there is no issue with UI Toolkit vs IMGUI drawing.
     
  9. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    20,740
    I remembered seeing an asset by @SisusCo on the store a while back that mentioned support for Odin.

    https://forum.unity.com/threads/component-names-press-f2-to-rename.1237720/

    Here's a quick test of it.

    Code (csharp):
    1. using UnityEngine;
    2. using Sirenix.OdinInspector;
    3.  
    4. public class Foo : SerializedMonoBehaviour
    5. {
    6.     [Button(ButtonSizes.Medium)]
    7.     [TabGroup("Enemies", "Enemy Data")]
    8.     [GUIColor(0.6f, 1.0f, 0.6f)]
    9.     public void SpawnRandomEnemy()
    10.     {
    11.      
    12.     }
    13. }

    upload_2023-8-4_17-20-22.png

    I briefly skimmed through the code for the asset and I didn't see anything specifically written for Odin. I'm a bit curious how it works but not so much that I want to do a deep dive into it.
     
    MadeFromPolygons likes this.
  10. John_Leorid

    John_Leorid

    Joined:
    Nov 5, 2012
    Posts:
    643
    If you derive your custom Editor from Odins Editor, it will work. But that's a special case. Without special if-defines (
    #if ODIN_INSPECTOR
    or something like that) your code would require Odin to exist to work. And you can't do that with more than one asset - and only with assets that support this (by proving the class to derive from and the if-define).

    (except in even more special cases where the assets already derive from one another and you derive from the one that is compatible with the other one)