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
3
Question by GeraldOBBI · Apr 27, 2011 at 07:25 PM · arrayinspectorenumnested

Enum drop down menu in inspector for nested arrays

Hi everyone,

I'm having an issue with enum values being reflected as their numeric values in the inspector when used in a nested array with Unity. Here's a cut down example of the code I'm trying to use.

public enum EnumType { Enum1, Enum2 }

public class ContainerClass : MonoBehavior { [Serializable] public class Constants { [Serializable] public class SubConstants { /.../ public EnumType EnumVals[] = null; }

     public SubConstants SubConsts = new SubConstants();
 }

 [SerializeField]List<Constants> _Attributes = new List<Constants>();

}

So what I'm seeing is that I can create and modify the list of Constants but when I go to edit the array of EnumType in SubConstants, it only shows numeric values and not a drop down box of values. I've also tried making the List an array with no change.

Comment
Add comment
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

2 Replies

· Add your reply
  • Sort: 
avatar image
3
Best Answer

Answer by yoyo · Apr 27, 2011 at 08:09 PM

Seems like the Unity Inspector has a bug with reflected type discovery. Rearranging the nesting of the classes as follows makes it work:

using System; using System.Collections.Generic; using UnityEngine;

public enum EnumType { Enum1, Enum2 }

[Serializable] public class SubConstants { /.../ public EnumType[] EnumVals = null; }

public class ContainerClass : MonoBehaviour { [Serializable] public class Constants { public SubConstants SubConsts = new SubConstants(); }

 [SerializeField]List<Constants> _Attributes = new List<Constants>();

}

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 · Jun 22, 2011 at 06:52 AM 0
Share

I just discovered the same thing - your post confirmed my suspicions/fears, thankyou! Did you report the bug to the devs? It's not a huge issue, but it would be nice to fix up!

avatar image Bovine · Oct 26, 2011 at 10:55 AM 0
Share

I have the same problem but no dice for me so far :o(

avatar image
1

Answer by TowerOfBricks · Sep 05, 2013 at 10:30 AM

In case the above does not work for you. It is possible to work around it using PropertyDrawers

Editor code

 [CustomPropertyDrawer(typeof(EnumAttr))]
 public class EnumEditor : PropertyDrawer {
     public override void OnGUI (Rect position, SerializedProperty prop, GUIContent label) {
         System.Enum v = EditorGUI.EnumPopup (position, label, (System.Enum)System.Enum.ToObject ((this.attribute as EnumAttr).enumType, prop.intValue));
         prop.intValue = System.Convert.ToInt32 (v);
     }
 }

Class code

 public class EnumAttr : PropertyAttribute {
     public System.Type enumType;
     
     public EnumAttr (System.Type enumType) {
         this.enumType = enumType;
     }
 }

Then for a field which is an enum

 [EnumAttr(typeof(Side))]
 public Side side = Side.Side1;
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

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

populate array values automatically in inspector 2 Answers

Making a user-friendly array with indices based on an enum 2 Answers

Array with multiple variables in Inspector 1 Answer

Rename array element name in inspector with enum 0 Answers

Nested enum shows as int in Inspector 2 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