Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
6
Question by artie · Jan 31, 2014 at 09:57 AM · arrayscustom-editor

Can I change inspector 'Element 0' to something else?

Ok, I know the trick of having a public string as the first element of a class that can change the name of the Element.

I'm wondering if I can change the whole thing without having to do that. I'm guessing a custom inspector like here: http://answers.unity3d.com/questions/26207/how-can-i-recreate-the-array-inspector-element-for.html

But what I'd like to have is something like:

 Enemy 1
 Enemy 2
 Enemy 3

etc. instead of Element, have that come up automatically.

Comment
Add comment · Show 4
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image TonyLi · Jan 31, 2014 at 02:35 PM 1
Share

Your guess is right. If you're not willing to make a public string the first field of your class, the only other solution I'm aware of is to write a custom inspector or property drawer.

avatar image artie · Jan 31, 2014 at 06:43 PM 0
Share

Not sure how or where to make that change. Several examples on that linked page, but I'm kinda lost. There's one that explicitly puts 'Element' in but it looks messy and didn't get many votes.

avatar image TonyLi · Jan 31, 2014 at 09:04 PM 0
Share

The examples are short. Try 'em out. One explicitly says JavaScript (UnityScript). The others are C#, btw. For the JavaScript one, you can change "Element "+x to just x to get rid of the "Element" part.

avatar image kushal_kadaba · Apr 18, 2014 at 03:39 AM 0
Share

Did you find the answer to this? $$anonymous$$ind of having the same issue.

6 Replies

· Add your reply
  • Sort: 
avatar image
6

Answer by Neogen13 · Oct 18, 2015 at 09:09 AM

@artie

Just had that propblem)

Custom function for arrays in Editor or PropertyDrawer instead of EditorGuiLayout.PropertyField();

  public void ShowArrayProperty(SerializedProperty list)
     {
         EditorGUILayout.PropertyField(list);
 
         EditorGUI.indentLevel += 1;
         for (int i = 0; i < list.arraySize; i++)
             {
                   EditorGUILayout.PropertyField(list.GetArrayElementAtIndex(i),  
                   new GUIContent ("Bla" + (i+1).ToString())); 
             }            
             EditorGUI.indentLevel -= 1;
     }

So you have:

 Bla 1
 Bla 2
 Bla 3

Hope it would help someone ^__^

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image gaabs · Dec 08, 2016 at 05:20 PM 2
Share

Could you please explain better where do I insert that script?

avatar image DDeathlonger gaabs · Dec 19, 2017 at 02:25 PM 0
Share

Throw this at the bottom of your script or make a new script: |`

 [UnityEditor.CustomEditor(typeof(ClassContainingTheList))]
 public class InspectorCustomizer : UnityEditor.Editor
 {
     public void ShowArrayProperty(UnityEditor.SerializedProperty list)
     {
         UnityEditor.EditorGUI.indentLevel += 1;
         for (int i = 0; i < list.arraySize; i++)
         {
             UnityEditor.EditorGUILayout.PropertyField(list.GetArrayElementAtIndex(i), new UnityEngine.GUIContent("Bla" + (i + 1).ToString()));
         }
         UnityEditor.EditorGUI.indentLevel -= 1;
     }

     public override void OnInspectorGUI()
     {
         ShowArrayProperty(serializedObject.FindProperty("NameOfListToView"));
     }
 }`
avatar image giangm9 DDeathlonger · Mar 06, 2019 at 09:28 AM 0
Share

I used your scripts but the default display is disabled, I added base.OnInspectorGUI() before ShowArrayProperty(serializedObject.FindProperty("NameOfListToView")); to show the default, but that makes list render twice, how do I edit the list ?

avatar image PixelFireXY · Apr 06, 2020 at 03:43 PM 0
Share

This is great! How can I use the value of a variable ins$$anonymous$$d of the constant "Bla"? If I have a list of struct and in this struct there is a string field, how can I call each element in the editor with:

  • variable value 1

  • variable value 2

  • variable value 3

Ins$$anonymous$$d of:

  • Bla 1

  • Bla 2

  • Bla 3

avatar image
4

Answer by jnt · Feb 22, 2018 at 08:54 PM

 #if UNITY_EDITOR
   public string Name;
 #endif

I'll go one-up on you @COAForce ;)

In my opinion this is the simplest and best way. Means you don't have any unwanted serialized data hanging around in your build.alt text


unity-array-naming.png (15.4 kB)
Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image kyle-misner-kriel · Jun 06, 2018 at 07:31 PM 0
Share

This only works if it's the first element and a string. "Name" is no longer important.

avatar image
0

Answer by Elecman · Mar 26, 2015 at 04:43 AM

In a PropertyDrawer you can do this by changing the GUIContent label like so: label.text = "test";

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by WalterEspinar · Jun 22, 2016 at 09:29 PM

Add this at the start: public string name;

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image huulong · Oct 20, 2016 at 04:28 PM 1
Share

The OP mentions the trick, it works for any public string field placed first, or for a private [SerializeField] string field.

avatar image DDeathlonger · Dec 19, 2017 at 03:30 PM 0
Share

That doesn't work for lists though.

avatar image
0

Answer by RyanNguyen · Sep 17, 2017 at 07:56 PM

For those who are having this problem. This is my solution

 public class PropertyWindow : EditorWindow
 {
 private void ArrayGUI(SerializedProperty property, string itemType, ref bool visible)
         {
             visible = EditorGUILayout.Foldout(visible, property.name);
             if (visible)
             {
                 EditorGUI.indentLevel++;
                 SerializedProperty arraySizeProp = property.FindPropertyRelative("Array.size");
                 EditorGUILayout.PropertyField(arraySizeProp);
 
                 for (int i = 0; i < arraySizeProp.intValue; i++)
                 {
                     EditorGUILayout.PropertyField(property.GetArrayElementAtIndex(i), new GUIContent(itemType + i.ToString()), true);
                 }
                 EditorGUI.indentLevel--;
             }
         }
 }

    

How to use

  private void OnGUI()
  {
        ArrayGUI(property, "Name", ref listVisibilityAttack);
  }

Hope this helps!.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
  • 1
  • 2
  • ›

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

32 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

need to shorten my code but unsure of how 3 Answers

Get ParticleSystem (Shuriken) to play from array of game objects C# 2 Answers

How to find the index of an Object in an Array 2 Answers

Advance through array elements with math (++)? 1 Answer

Attempt at creating an array of text files results in different errors 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges