Search Unity

Can I change a component's inspector title bar text?

Discussion in 'Editor & General Support' started by VoodooDetective, Aug 27, 2020.

  1. VoodooDetective

    VoodooDetective

    Joined:
    Oct 11, 2019
    Posts:
    239
    Is there any way to change a component's inspector title bar based on the field values? For instance, if a reference is set for an object field, can I change the component titlebar to say the name of that object?
     
  2. DiegoDePalacio

    DiegoDePalacio

    Unity Technologies

    Joined:
    Oct 28, 2009
    Posts:
    507
    Hi @VoodooDetective,

    Unfortunately, you can't change the name of the `Inspector` tab of the Editor.

    You can have title bars with customized text by creating Editor Windows: https://docs.unity3d.com/Manual/editor-EditorWindows.html

    However, the customized title will not change depending on the content that you have assigned to the field values.

    Why do you want it?... Maybe we can find another way to achieve what you want without changing the `Inspector` title bar ;)


    I hope this helps!
     
    VoodooDetective likes this.
  3. VoodooDetective

    VoodooDetective

    Joined:
    Oct 11, 2019
    Posts:
    239
    Hey @DiegoDePalacio, I have a script that takes a component reference from an object with many components of the same type. It's impossible to differentiate between then by looking at the reference field since they all have the same game object name and the same script name.

    Example:
    The object with many of the same components is called "Test." The script is called "Test Script."
    All references to ANY of the components will all be named "Test (TestScript)."

    Any help would be appreciated!
     
  4. DiegoDePalacio

    DiegoDePalacio

    Unity Technologies

    Joined:
    Oct 28, 2009
    Posts:
    507
    Hey @VoodooDetective,

    What you can do is to write a PropertyDrawer in where the label contains the Instance ID of the component that is being referenced.

    With it, you'll be able to recognize exactly which component is being referenced.

    If you go down this path, you can also use the Debug mode of the Inspector window to see the Instance ID of the components attached to a certain GameObject.

    You can find more information about PropertyDrawer here: https://docs.unity3d.com/Manual/editor-PropertyDrawers.html

    And about InstanceID here: https://docs.unity3d.com/ScriptReference/Object.GetInstanceID.html

    Finally about Debug mode in the Inspector window here: https://docs.unity3d.com/Manual/InspectorOptions.html


    I hope this helps!
     
    SuperBiome and VoodooDetective like this.
  5. VoodooDetective

    VoodooDetective

    Joined:
    Oct 11, 2019
    Posts:
    239
    DiegoDePalacio likes this.
  6. JPGameDev

    JPGameDev

    Joined:
    May 9, 2021
    Posts:
    1
  7. SisusCo

    SisusCo

    Joined:
    Jan 29, 2019
    Posts:
    1,331
    This is now also possible to do dynamically based on member values using Component Names.

    Here's my test code:

    Code (CSharp):
    1. using UnityEngine;
    2. using Sisus.ComponentNames;
    3.  
    4. public class TestScript : MonoBehaviour
    5. {
    6.     public GameObject target;
    7.  
    8.     void OnValidate() => this.SetName("Test: " + (target == null ? "null" : target.name));
    9. }
    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. public class References : MonoBehaviour
    4. {
    5.     public TestScript[] testScripts;
    6. }
    And the end result:

    TestScript.png
     
    Atomiz2002 and VeryBadPenny like this.
  8. VeryBadPenny

    VeryBadPenny

    Joined:
    Jun 3, 2018
    Posts:
    40
    Amazing highly targeted tool, was looking for exactly this. Insta-buy on the Asset Store. Thank you so much.
     
    SisusCo likes this.