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. Join us on Dec 8, 2022, between 7 am & 7 pm EST, in the DOTS Dev Blitz Day 2022 - Q&A forum, Discord, and Unity3D Subreddit to learn more about DOTS directly from the Unity Developers.
    Dismiss Notice
  3. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    Dismiss Notice

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:
    764
    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
    mgear, steego and BetaMark like this.
  2. BetaMark

    BetaMark

    Joined:
    Sep 27, 2014
    Posts:
    208
    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:
    764
    @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:
    3
    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:
    764
    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:
    764
  7. trueh

    trueh

    Joined:
    Nov 14, 2013
    Posts:
    42
    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:
    764
    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:
    42
  10. SisusCo

    SisusCo

    Joined:
    Jan 29, 2019
    Posts:
    764
    @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:
    42
    @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:
    764
    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!