Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 /
  • Help Room /
avatar image
0
Question by revraptor · Dec 09, 2020 at 02:33 PM · editor-scriptingeditorguicustom-inspectorcustomeditor

Custom Editor showing twice?

Hi

I've been trying to make a custom editor to show lists in a different manner in my scriptable objects. I kept having an issue where it wasn't rendering right (It would show twice in the inspector even though it should only show once.)

While trying to find a fix, I found a tutorial about the same thing I was doing, so I tried following it. What's really confusing is when I followed it I had the same issue.

This is what the issue I'm getting looks like, since it's sort of hard to explain in words: alt text

It should only be showing The Size and list of elements once, instead it's showing them twice. I tried googling for solutions and the only one I could find suggested setting the layout to default and closing/reopening Unity. I tried this, as well as uninstalling all versions of Unity/Unity Hub and reinstalling, and tried updating versions of unity to the latest stable release.

This is the ListEditor class: using UnityEditor; using UnityEngine; using System;

 [Flags]
 public enum ListEditorOptions
 {
     None = 0,
     ListSize = 1,
     ListLabel = 2,
     ElementLabels = 4,
     Buttons = 8,
     Default = ListSize | ListLabel | ElementLabels,
     NoElementLabels = ListSize | ListLabel,
     All = Default | Buttons
 }
 
 public static class ListEditor
 {
 
     private static GUIContent
         moveButtonContent = new GUIContent("\u21b4", "move down"),
         duplicateButtonContent = new GUIContent("+", "duplicate"),
         deleteButtonContent = new GUIContent("-", "delete"),
         addButtonContent = new GUIContent("+", "add element");
 
     private static GUILayoutOption miniButtonWidth = GUILayout.Width(20f);
 
     public static void Show(SerializedProperty list, ListEditorOptions options = ListEditorOptions.Default)
     {
         if (!list.isArray)
         {
             EditorGUILayout.HelpBox(list.name + " is neither an array nor a list!", MessageType.Error);
             return;
         }
 
         bool
             showListLabel = (options & ListEditorOptions.ListLabel) != 0,
             showListSize = (options & ListEditorOptions.ListSize) != 0;
 
         if (showListLabel)
         {
             EditorGUILayout.PropertyField(list);
             EditorGUI.indentLevel += 1;
         }
         if (!showListLabel || list.isExpanded)
         {
             SerializedProperty size = list.FindPropertyRelative("Array.size");
             if (showListSize)
             {
                 EditorGUILayout.PropertyField(size);
             }
             if (size.hasMultipleDifferentValues)
             {
                 EditorGUILayout.HelpBox("Not showing lists with different sizes.", MessageType.Info);
             }
             else
             {
                 ShowElements(list, options);
             }
         }
         if (showListLabel)
         {
             EditorGUI.indentLevel -= 1;
         }
     }
 
     private static void ShowElements(SerializedProperty list, ListEditorOptions options)
     {
         bool
             showElementLabels = (options & ListEditorOptions.ElementLabels) != 0,
             showButtons = (options & ListEditorOptions.Buttons) != 0;
 
         for (int i = 0; i < list.arraySize; i++)
         {
             if (showButtons)
             {
                 EditorGUILayout.BeginHorizontal();
             }
             if (showElementLabels)
             {
                 EditorGUILayout.PropertyField(list.GetArrayElementAtIndex(i));
             }
             else
             {
                 EditorGUILayout.PropertyField(list.GetArrayElementAtIndex(i), GUIContent.none);
             }
             if (showButtons)
             {
                 ShowButtons(list, i);
                 EditorGUILayout.EndHorizontal();
             }
         }
         if (showButtons && list.arraySize == 0 && GUILayout.Button(addButtonContent, EditorStyles.miniButton))
         {
             list.arraySize += 1;
         }
     }
 
     private static void ShowButtons(SerializedProperty list, int index)
     {
         if (GUILayout.Button(moveButtonContent, EditorStyles.miniButtonLeft, miniButtonWidth))
         {
             list.MoveArrayElement(index, index + 1);
         }
         if (GUILayout.Button(duplicateButtonContent, EditorStyles.miniButtonMid, miniButtonWidth))
         {
             list.InsertArrayElementAtIndex(index);
         }
         if (GUILayout.Button(deleteButtonContent, EditorStyles.miniButtonRight, miniButtonWidth))
         {
             int oldSize = list.arraySize;
             list.DeleteArrayElementAtIndex(index);
             if (list.arraySize == oldSize)
             {
                 list.DeleteArrayElementAtIndex(index);
             }
         }
     }
 }

And this is where I'm calling it from:

         public override void OnInspectorGUI()
         {
             soTarget.Update();
             EditorGUI.BeginChangeCheck();
 
             ListEditor.Show(soTarget.FindProperty("possibleGenerators"));

             if (EditorGUI.EndChangeCheck() || GUI.changed)
             {
                 Undo.RecordObject(myTarget, "Save Cavern Parameters");
                 EditorUtility.SetDirty(myTarget);
                 soTarget.ApplyModifiedProperties();
                 AssetDatabase.SaveAssets();
             }
 
             EditorGUI.EndChangeCheck();
         }


untitled.png (23.4 kB)
Comment
Add comment · Show 1
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 MostHated · May 29, 2021 at 09:17 PM 0
Share

I am having this issue as well. In 2019 it was fine, but I imported into newer versions and it draws the same way as yours now without any code changes. Did you ever find out anything about it?

alt text

It seems to be anything within a top-level foldout. Not the top level itself. Also not sub-foldouts

alt text

0 Replies

· Add your reply
  • Sort: 

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

225 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 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 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 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 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 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 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 avatar image

Related Questions

Webview in custom Unity Editor Window? 0 Answers

EditorGUILayout.Popup with an array of GameObject? 0 Answers

Using CustomEditor caused error which was CS0246. 0 Answers

Making a custom editor window much like the Animator window? 0 Answers

GUI / Inspector Help,CustomEditor with A callback Function 0 Answers


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