Search Unity

Feature Request Add a possibility to set custom names for MonoBehaviour

Discussion in 'Editor & General Support' started by SolidAlloy, Jan 28, 2021.

  1. SolidAlloy

    SolidAlloy

    Joined:
    Oct 21, 2019
    Posts:
    58
    In an Editor tool I'm developing, MonoBehaviour components are added programmatically and I would like to prevent users from adding them using the Add Component button. There is a couple ways to do it:
    - Make MonoBehaviour a nested class.
    - Pass empty string to the AddComponentMenu attribute.

    However, I need MonoBehaviours to have custom names. Currently, it is only possible if you set it in the AddComponentMenu prepending the name with "Scripts/", e.g.
    [AddComponentMenu("Scripts/CustomName")]
    . But as soon as I add an AddComponentMenu, it obviously appears in the context menu and cannot be hidden.

    I think that the best way to overcome this is to create a separate attribute called something like CustomNameAttribute. A string passed to it will be the custom name of the component in Inspector, but it will appear under its default name in the component menu list (or under the custom path if set in AddComponentMenu).