Search Unity

Component Names - Press F2 to Rename

Discussion in 'Assets and Asset Store' started by SisusCo, Feb 9, 2022.

  1. SisusCo

    SisusCo

    Joined:
    Jan 29, 2019
    Posts:
    1,330
    component-names.png

    Ever had trouble distinguishing multiple colliders on the same GameObject from each other?

    Ever wished you could rename that generic "Event Trigger" component to something a little more descriptive like "On Click Open Settings"?

    What if you could attach little notes to your components to provide some clarifying context?

    Wouldn't it be great if you could see the current state of that "Health" component right in the title without having to unfold it?

    Now you can!

    Component Names integrates seamlessly with the Inspector and makes it possible to rename components at will as if it was a native feature.

    renaming-components.gif

    Features
    • Select a component's header and press F2 to start renaming it (or select "Rename" from the context menu if your keyboard is broken).
    • Default name is shown in parentheses after the custom name automatically by default.
    • Custom component names can be seen inside Object fields.
    • All custom name data is fully stripped from builds.
    Additional Features For Coders
    • Acquire custom component names in code via Component.GetName extension method (great for debugging!).
    • Link component name to its current state by using Component.SetName extension method in OnValidate.
    • Make Component.name and Component.ToString return custom component names by deriving from custom base class.
    Compatibility
    • Compatible with Power Inspector, Odin Inspector and all your other custom editors.
     
    Last edited: Feb 10, 2022
  2. BetaMark

    BetaMark

    Joined:
    Sep 27, 2014
    Posts:
    229
    Oh man, this has been on my "please add this to unity" wish list since the 4.x days.

    Any chance this feature will get added to PowerInspector? I'm looking the features over there, and I think I'd want to go all in with PowerInspector on my project, but I'd hate to miss out on this feature.
     
  3. SisusCo

    SisusCo

    Joined:
    Jan 29, 2019
    Posts:
    1,330
    @BetaMark Ouch, that's a pretty lengthy wait!

    I've been mulling over this functionality since 2019 (after I stumbled upon this thread). I've tried out a couple of different approaches to solving this over the years, but never was able to put together anything up to a standard I was satisfied with - until I finally had a Eureka moment more recently and this is the end result :)

    I don't have any plans to add built-in component renaming functionality to Power Inspector, however Component Names is fully compatible with Power Inspector as well.

    Rename Components in Power Inspector.png
     
  4. JustusPan

    JustusPan

    Joined:
    Jun 21, 2018
    Posts:
    7
    If I change Inspector to Debug mode, and change the script of a component with its extended class which has different name. Then the header name could not refresh correctly.

    If I press F2 and delete all string and press enter to clear the name, the old name are still there.
    and the string in the rename input editor will become "Melee1 <color=grey>(Melee Weapon)</color>" next time. In this specific case, the real name of new script is "PP Melee Weapon"

    I think we should have a "Clear all meta data of Component Names" option in the context menu.
     
    Last edited: Sep 20, 2022
  5. SisusCo

    SisusCo

    Joined:
    Jan 29, 2019
    Posts:
    1,330
    Hey @JustusPan thanks for letting me know about this. I'll investigate how to fix these issues that happen if an attached component's type is swapped to a different in debug mode.

    All existing component name meta data should get cleared when you give a component a blank name, just like you tried, but in this case things don't seem to be working as they should after the type change. If it's possible, removing the component, and re-adding it should cause all the corrupted metadata to get cleared. But I'll investigate on my side how to resolve situations like this automatically.
     
    Last edited: Sep 20, 2022
    JustusPan likes this.
  6. SisusCo

    SisusCo

    Joined:
    Jan 29, 2019
    Posts:
    1,330
  7. trueh

    trueh

    Joined:
    Nov 14, 2013
    Posts:
    74
    Hello:

    In current Unity 2021.3 LTS, the component name is not showing in the inspector until it is not changed for the second time.

    Also, after uninstalling the asset, a hidden object remains in the hierarchy (NameContainer).

    Regards.
     
  8. SisusCo

    SisusCo

    Joined:
    Jan 29, 2019
    Posts:
    1,330
    Hey @trueh !

    I'll check the asset in Unity 2021.3 and starting working on a fix. Thanks for letting me know!

    If you want to remove Component Names from a project you can use the uninstall tool I've attached below to clean up your scenes from any leftover empty name containers.
     

    Attached Files:

  9. trueh

    trueh

    Joined:
    Nov 14, 2013
    Posts:
    74
  10. SisusCo

    SisusCo

    Joined:
    Jan 29, 2019
    Posts:
    1,330
    @trueh I managed to track down what was causing the issue and have now a fix for it. I'll submit the fix to the asset store for review today, and it'll probably become available for download early next week.

    If you'd like to get your hands on the fixed version before that just drop me a PM and I can send it your way.
     
  11. trueh

    trueh

    Joined:
    Nov 14, 2013
    Posts:
    74
    @Thank you @SisusCo. Don't worry, I will wait for the update in the Asset Store :)
     
    SisusCo likes this.
  12. GoldenJude

    GoldenJude

    Joined:
    May 31, 2018
    Posts:
    1
    Hey, @SisusCo really liking the plugin so far. I was wondering though, would it be at all possible to have the custom names also show up when the component is being referenced as a parameter in a UnityEvent ?

    Example:


    The method being called in this instance is
    Code (CSharp):
    1. public void PrintComponentName(NamedComponent component)
    2. {
    3.     Debug.Log(component.GetName());
    4. }
     
  13. SisusCo

    SisusCo

    Joined:
    Jan 29, 2019
    Posts:
    1,330
    Hey @GoldenJude , glad to hear you're enjoying plugin :)

    Ah right, I had not realized that element is not currently covered. I'll investigate if I can make it reflect the custom name as well.

    Thanks for the feedback!
     
  14. XBLANKZ

    XBLANKZ

    Joined:
    Aug 1, 2019
    Posts:
    3
    HI, it seems that when I select multiple, and it is the same type or script the component renames is not properly renamed
    Multiple
    upload_2022-12-11_18-42-56.png

    Single
    upload_2022-12-11_18-43-34.png

    @SisusCo
     
  15. SisusCo

    SisusCo

    Joined:
    Jan 29, 2019
    Posts:
    1,330
    Hi @XBLANKZ Thanks for letting me know about the shortcoming!
    I'll try to get multi-editing working properly for the next version.
     
  16. JustusPan

    JustusPan

    Joined:
    Jun 21, 2018
    Posts:
    7
    Bug Report: Deleted component in prefab variant could not show its name correctly

    Before deletion
    upload_2023-1-9_19-3-14.png

    After deletion
    upload_2023-1-9_19-4-0.png
     
  17. JustusPan

    JustusPan

    Joined:
    Jun 21, 2018
    Posts:
    7
    this issue seems will also affect the base prefab, the deleated component in variant prefab also eliminate the names in the base prefab. And I could not assign names in base prefab anymore.
    This reveal some issues under nested prefab workflow.
    Could you please look into this problem? @SisusCo
     
  18. JustusPan

    JustusPan

    Joined:
    Jun 21, 2018
    Posts:
    7
    upload_2023-1-13_3-20-13.png

    These warning will happen each time I open unity now. Is there anyway to delete all meta data created by this plugin and remove ComponentName plugin safely?
     
  19. JustusPan

    JustusPan

    Joined:
    Jun 21, 2018
    Posts:
    7
    Another Bug: In following two situations, you will see different names of same component of a same prefab( this prefab is a prefab variant of a base prefab)
    1) single click prefab in Project window, then inspector will show the components of that prefab
    2) double click prefab in Project window, then inspector will show the components of that prefab
     
  20. SisusCo

    SisusCo

    Joined:
    Jan 29, 2019
    Posts:
    1,330
    Hey @JustusPan , thank you for letting me know about all these findings with prefab variants! I'll investigate how to fix them.

    This tool can be used to remove all component name metadata from the all open scenes or selected objects. It can be used both before or after Component Names has been uninstalled.
     
    JustusPan likes this.
  21. lgarczyn

    lgarczyn

    Joined:
    Nov 23, 2014
    Posts:
    68
    I'm a bit worried about buying this asset, there's no mention as to how it is implemented.

    Do I have to inherit from a special behavior?

    Does it override every monobehavior drawer?
     
  22. SisusCo

    SisusCo

    Joined:
    Jan 29, 2019
    Posts:
    1,330
    Hey @lgarczyn !

    You don't need to inherit from any special class; all components can be renamed by default, including built-in ones.

    There is a completely optional base behaviour included with the package, but it doesn't do anything except replaces the
    name
    property and the
    ToString()
    method to make working in code a tiny bit more convenient.
    Code (CSharp):
    1. public abstract class BaseBehaviour : MonoBehaviour
    2. {
    3.     public virtual new string name
    4.     {
    5.         get => this.GetName();
    6.         set => this.SetName(value);
    7.     }
    8.  
    9.     public override string ToString() => this.GetName();
    10. }
    But even without replacing these members, you can also always get or set the name of any component in code using the
    GetName
    and
    SetName
    extension methods.

    Component Names does not use a custom editor at all, so there should never be any incompatibility issues with other custom editors.

    The custom component names are injected to Unity's internal component name cache which makes them automatically show up in the Inspector. The renaming GUI is handled by opening a borderless editor window with a text field on top of the component header when you press F2.

    The property drawers used by Object fields and UnityEvents are overridden, for the purposes of having custom component names be shown in them. This does mean that the custom Object property drawer included with Odin inspector for example will get overridden by the one in Component Names:
    component-names-and-odin-inspector.gif
     
    Last edited: Jun 13, 2023
  23. dev_rateme

    dev_rateme

    Joined:
    Nov 19, 2020
    Posts:
    1
    @SisusCo If my repo in nested in folder thats ends in "Data", Unity inspector will be very slow. I investigated and found the isses in the method GetXMLDocumentationFilepath.
     
  24. SisusCo

    SisusCo

    Joined:
    Jan 29, 2019
    Posts:
    1,330
    @dev_rateme Thanks for letting me know! I'll submit a fix for this asap.
     
  25. tacuax

    tacuax

    Joined:
    Dec 17, 2023
    Posts:
    1
    Hey! I'm sorry, maybe this is something obvious but how do I install it? I just bought it but I cant change my components name yet. Thanks
     
  26. SisusCo

    SisusCo

    Joined:
    Jan 29, 2019
    Posts:
    1,330
    Hey @tacuax , thank you for the purchase :)

    You can use the Package Manager, which can be opened using the
    Window > Package Manager
    menu item, to install assets that you own into a project.
    open-package-manager.png

    In the Package Manager window select
    My Assets
    from the
    Packages
    dropdown menu, and then select
    Component Names
    in the list on the left side.
    download-and-import.png

    You should then see two buttons on the right side that can used to first download the asset and then import it into the project.

    After importing the asset into your project you should immediately begin being able to rename components by clicking on the component's header in the Inspector and then pressing F2.
     
  27. lgarczyn

    lgarczyn

    Joined:
    Nov 23, 2014
    Posts:
    68
    That's pretty damn clever! Where are the component names stored? Are they shared between projects?
     
    SisusCo likes this.
  28. SisusCo

    SisusCo

    Joined:
    Jan 29, 2019
    Posts:
    1,330
    Component names are stored on a per-component basis, so they are not shared between multiple components nor projects.

    When you rename a particular component on a game object, what happens behind the scenes is that a new game object is generated with hideFlags set to HideInHierarchy and tag set to "EditorOnly". This has the effect that the game object will not be visible in the Hierarchy view, and it will only exist in the editor, and get automatically stripped from builds by Unity. This invisible game object will be stored as a child object of the game object containing the renamed component.

    GameObject
    ↳ NameContainer(EditorOnly)

    A component is attached to this invisible game object, to hold the custom name given to the component in a serialized field. This way it gets serialized alongside the renamed component as part of the same scene asset.

    Storing the name as part of the same asset like this, rather than, say, in some external database, has some benefits:
    1. If a game object holding a renamed component is deleted, component name data for its components will naturally also get automatically deleted alongside it.
    2. If a game object holding a renamed component is duplicated, component name data for its components will also get duplicated automatically alongside it, so the components in the duplicate will all retain their custom names.
    3. Similarly, if an entire scene asset is deleted or duplicated, all custom component name data for all the components in the scene will also get automatically deleted or duplicated.
    4. If a renamed component is deleted, the name container can easily detect that the component its targeting no longer exists and delete itself.
    5. If a renamed component is dragged into another game object, the name container can also easily detect that the component its targeting now exist in a different game object, and can migrate itself as well to be a child of the same game object.
     
  29. lgarczyn

    lgarczyn

    Joined:
    Nov 23, 2014
    Posts:
    68
    Oh, that's smart. I thought it was done with some kind of serialization magic or monster db.

    Any problems with prefab overrides? I use a lot of nested prefab and prefab variants
     
  30. SisusCo

    SisusCo

    Joined:
    Jan 29, 2019
    Posts:
    1,330
    Oh yeah, handling prefabs is tough...

    There is support added for component name overriding in prefab variants, made possible by the fact that the custom name is held in a serialized field. If you give a custom name to a base prefab, and then remove the custom name in a prefab variant, that should also work - in this case the invisible name container will not be removed from the variant (since Unity does not allow deleting whole game objects in prefab variants), but the name data on it is set to "", which has the same effect in the Inspector.

    I would still recommend trying to avoid overriding custom component names in prefab variants to be honest. I wouldn't be surprised if it's still possible to somehow throw the system for a loop by applying/reverting changes from variants to the base prefab, deleting renamed components in prefab variants or base prefabs, or something. I've tried to add handling for many edge case scenarios I could think of, but it gets really tricky to cover all the bases when it comes to prefabs - especially with all the restrictions for when game objects are allowed to be deleted and when not.
     
  31. lgarczyn

    lgarczyn

    Joined:
    Nov 23, 2014
    Posts:
    68
    As of Unity 2022, you can absolutely delete a gameobject in a prefab variant
     
    SisusCo likes this.
  32. SisusCo

    SisusCo

    Joined:
    Jan 29, 2019
    Posts:
    1,330
    Oh you're right, I've completely missed that this became possible to do in version 2022.2! That's awesome, that'll make my life so much easier - after I drop support for the earlier versions at least.
     
  33. oppay48

    oppay48

    Joined:
    Jan 7, 2016
    Posts:
    2
    Hello,

    This asset is great, really love it, but i got a problem with my custom event. They name aren't displayed properly since i installed this asset.

    upload_2024-3-7_14-35-6.png

    The events themselve are simple unity event that take on parameter.
    upload_2024-3-7_14-36-44.png

    What do i have to change so it compatible ?
     
    Last edited: Mar 8, 2024
  34. SisusCo

    SisusCo

    Joined:
    Jan 29, 2019
    Posts:
    1,330
    @oppay48 Those should be supported automatically, I'll take a look. Thanks for letting me know!
     
    oppay48 likes this.
  35. oppay48

    oppay48

    Joined:
    Jan 7, 2016
    Posts:
    2
    @SisusCo
    I try in a empty project, just to make sure i didn't miss anything, but the result is the same.

    This code :
    Code (CSharp):
    1. public class UnityEventBool_Test : MonoBehaviour
    2. {
    3.     public UnityEventBool m_NameOfBoolEvent;
    4.     void Start()
    5.     {
    6.         m_NameOfBoolEvent?.Invoke(true);
    7.     }
    8.  
    9.     void TestBoolEvent(bool a_value)
    10.     {
    11.         Debug.Log("Bool event value is + " + a_value);
    12.     }
    13. }
    14.  
    15. [System.Serializable]
    16. public class UnityEventBool : UnityEvent<bool>{}
    17.  
    Display should display like so:
    upload_2024-3-8_10-15-20.png

    But it change and display like this instead:
    upload_2024-3-8_10-16-29.png
     
    SisusCo likes this.
  36. SisusCo

    SisusCo

    Joined:
    Jan 29, 2019
    Posts:
    1,330
    @oppay48 The issue with unity event drawer names in the latest Unity versions will be fixed in the next version. I'm submitting it to the asset store for review now.

    UnityEventDrawer.png

    By the way, you no longer need to define non-generic unity event types; Latest versions of Unity can serialize fields of generic types as well :)
     
    oppay48 likes this.
  37. DWO_

    DWO_

    Joined:
    Feb 19, 2014
    Posts:
    26
    Hey there, I love this plugin, just wanted to ask if there is a specific define symbol I can check against to see if this plugin is in use or not (similar to how Odin Inspector defines a ODIN_INSPECTOR preprocessor symbol)?

    I see there is already the define SHOW_NAME_CONTAINERS symbol and was wondering if this was fine to use in a preprocessor conditional to check if the package is installed?
     
  38. SisusCo

    SisusCo

    Joined:
    Jan 29, 2019
    Posts:
    1,330
    Hey @DWO_ ! I'm happy to hear you're enjoying the asset :)

    There is no scripting define symbol at the moment for detecting if Component Names is installed or not unfortunately. SHOW_NAME_CONTAINERS is just for my own use during development, and won't automatically get added to the project's scripting define symbols list.

    I can make an update to Component Names that converts it into a package, listed under the Packages folder instead of the Assets folder. After this you could create your own scripting define for it using the Version Defines section of your Assembly Definition Assets.
     
  39. DWO_

    DWO_

    Joined:
    Feb 19, 2014
    Posts:
    26
    Yeah, that would be fantastic! That would definitely work for my use case. Thank you so much @SisusCo!
     
    SisusCo likes this.
  40. SisusCo

    SisusCo

    Joined:
    Jan 29, 2019
    Posts:
    1,330
    Hey @DWO_ , the update that turns Component Names into a package is now live.
     
    DWO_ likes this.
  41. DWO_

    DWO_

    Joined:
    Feb 19, 2014
    Posts:
    26
    SisusCo likes this.
  42. DWO_

    DWO_

    Joined:
    Feb 19, 2014
    Posts:
    26
    By the way, it seems like the package manifest for the new version seems to be incorrect? The asset store (& package manager) version shows 1.0.9 whereas the package manifest for the actual package still shows 1.0.8.
     
  43. SisusCo

    SisusCo

    Joined:
    Jan 29, 2019
    Posts:
    1,330
    @DWO_ Right you are, it should be 1.0.9 in both places - thanks for the heads up! I'm still getting used to this new submission workflow :D
     
    DWO_ likes this.