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. Dismiss Notice

I cannot rename list element names in the inspector

Discussion in 'Scripting' started by AleksandarCic, Feb 27, 2021.

  1. AleksandarCic

    AleksandarCic

    Joined:
    Sep 5, 2020
    Posts:
    9
    Hiya.
    I was trying to clean up my inspector view a bit and wanted to spice up my list/arrays names in the inspector.
    I knew that i should've made a public string called "name" and insert it in the base class for my list.
    Then they changed the list/array ui a bit in the 2020.2 and this doesnt work anymore is there any way that i can still rename list/array names in any way without writing a custom inspector for it?
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,336
    I'm sorry I don't quite understand what you're doing.

    If you have an array/list called "Animals" and want to instead call it "Vegetables," by default Unity will not be able to reconnect that, but there are helper decorators:

    https://docs.unity3d.com/ScriptReference/Serialization.FormerlySerializedAsAttribute.html

    You can also go in and hand-edit the scenes and/or prefabs (they are just text files) and rename the actual fields, which is what I prefer to do.
     
  3. AleksandarCic

    AleksandarCic

    Joined:
    Sep 5, 2020
    Posts:
    9
    Maybe i should've explained it better
    upload_2021-2-27_21-15-12.png
    I meant chaning the text from "Element 0" to the some string varriable which is name in this case.
     
  4. seejayjames

    seejayjames

    Joined:
    Jan 28, 2013
    Posts:
    685
    AFAIK no, but if there is, I'd like to hear about it. "Element N" is just Unity giving your indices generic names. If you really want new names, don't use lists, use individual objects. (unless there is a way to rename indices!)
     
  5. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,697
  6. Elango

    Elango

    Joined:
    Jan 27, 2016
    Posts:
    107
    In your case, just move the Name variable above the rest in the code.

    Code (CSharp):
    1.         public string name;
    2.         public int texturesID;
    3.         public float rarity;
    Instead of this:
    Code (CSharp):
    1.         public int texturesID;
    2.         public float rarity;
    3.         public string name;
     
    safaleventoglu and Putcho like this.
  7. AleksandarCic

    AleksandarCic

    Joined:
    Sep 5, 2020
    Posts:
    9
    thank you it works now