• 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 /
This question was closed Dec 05, 2013 at 01:49 AM by clunk47 for the following reason:

The question is answered, right answer was accepted

avatar image
Question by ashleybeshir · Aug 27, 2013 at 05:19 PM · c#inspectorenumwont stop

c# enum wont show in inspector

 using UnityEngine;
 using System.Collections;
 
 [System.Serializable]
 public class Items{
 
     public string name;
     public string description;
     public int id;
     public Texture2D icon;
     public GameObject gobject;
     public enum lolol{weapon,weapon2,health,armor};
     
 }


 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 
 public class Inventorya : MonoBehaviour {
     public List<Items> Inventory;
     public Items[] bag;
     public enum hello{};
     

on the list and array it shows the name descrip etc but not the enum one. it doesnt even show the hello enum in the description in the inspector.

Comment
skipadu
Necronomicron
dCalle
felixmann
bowserscastle
ntxr
zanouk
unity_17194192410E90131A21

People who like this

8 Show 5
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 clunk47 · Aug 29, 2013 at 01:39 AM 1
Share

If an answer helped and you have solved your issue, please accept an answer.

avatar image GameDevSA · Mar 14, 2018 at 03:16 AM 0
Share

There's a better solution.

 [System.Serializable]
     public enum PieceType
     {
         Hero,
         Moveable,
         Solid,
         Empty
     }
 
     public PieceType pieceType;

You just need to make the enum serializable.

avatar image haruna9x GameDevSA · Mar 14, 2018 at 07:07 AM 0
Share

There is nothing to comment on this question. He declared the enum, but he did not use it for any variables. And of course, it will not appear in the Inspector.

Why can people still add comments to a closed question?

avatar image ForceVII · Oct 17, 2020 at 02:08 PM 0
Share

Old post but for news: Don't use [Header] and it will work.

avatar image Bunny83 ForceVII · Oct 17, 2020 at 03:09 PM 0
Share

What do you mean? I just tried putting a Header attribute on an enum field and it shows up as it should.

 public enum ETestEnum { Foo, Bar }
 [Header("Enum Header")]
 public ETestEnum enumField;

header attribute on enum field

3 Replies

  • Sort: 
avatar image
Best Answer

Answer by clunk47 · Aug 28, 2013 at 12:33 AM

Example of how to use an enum and allow it to show in inspector:

 using UnityEngine;
 using System.Collections;
 
 public class Example : MonoBehaviour 
 {
     //Define Enum
     public enum TestEnum{Test1, Test2, Test3};
     
     //This is what you need to show in the inspector.
     public TestEnum Tests;
 }
 
Comment
Imawizrd
Dismortus
paprocjo
Julian-Glenn
roddles
noelyahan
Cupava
jprocha101
adi4x
the_game_maker
virgiliu
MFKJ
dchen05
Zeoli
Acerkake
And 44 more...

People who like this

59 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 ChrisRede · Feb 16, 2020 at 07:45 PM 0
Share

In these two lines i finally understood enums!

avatar image

Answer by fafase · Aug 27, 2013 at 05:35 PM

I think you are using it wrong. You want to declare the enum outside of the class and create an instance inside the class:

 public enum Lolol{Weapon,Weapon2,Health,Armor};
 
 public class Items{
  
 public string name;
   public string description;
   public int id;
   public Texture2D icon;
   public GameObject gobject;
   public enum lolol{weapon,weapon2,health,armor};
   public Lolol instanceOfEnum;
   void Start(){
      instanceOfEnum = Lolol.Armor;
   }
 }

I also changed the way you wrote it, by convention enumeration are all cap letters (old c way). But we can also see cap front and cap for members.

Comment
smrt_co

People who like this

1 Show 3 · 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 ashleybeshir · Aug 27, 2013 at 08:08 PM 0
Share

it works thats the funny thing but if it does show error later on i will use your method

avatar image Bunny83 · Aug 28, 2013 at 12:42 AM 1
Share

It won't give you errors, but your enum type is now a nested type. So everytime you want to use it outside of your Items class you have to use:

 someInstance.option = Items.lolol.weapon;

btw: for God's sake you declare a new type here, so give it a meaningful name which should start with a capital letter.

avatar image fafase · Aug 28, 2013 at 05:37 AM 1
Share

Fact is the method you are using makes sense if you are about to use your enum ONLY in that class and nowhere else. You then might as well make it private. Or you end up with what is described above

 Items.lolol.member;

The other way would be to put it outside and public so that you can use it anywhere and you gain one level of dereferenciation.

avatar image

Answer by flaviusxvii · Aug 27, 2013 at 05:26 PM

Why would it show? The enum itself is a list of possible values for some other field. You'll need a custom editor.

http://docs.unity3d.com/Documentation/ScriptReference/EditorGUILayout.EnumPopup.html

Comment

People who like this

0 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 ashleybeshir · Aug 27, 2013 at 05:36 PM 1
Share

thank you for your answer but i found a simple solution. under the public GameObject gobject; i wrote public lolol option; this showed up in the inspector straight away

avatar image NonGamingCoder · Aug 29, 2013 at 10:07 AM 1
Share

You don't need a custom editor to show a enum.

Unity Answers is in Read-Only mode

Unity Answers content will be migrated to a new Community platform and we are aiming to launch a public beta on June 13. Please note, Unity Answers is now in read-only so we can prepare for the final data migration.

For more information and updates, please read our full announcement thread in the Unity Forum.

Follow this Question

Answers Answers and Comments

24 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

Related Questions

Variable has not been assigned error 2 Answers

Values lost? 1 Answer

How to control serialized variables over the inspector pane? 1 Answer

Problem using EditorGUILayout.ObjectField with custom type 1 Answer

Automatically create enum based on class children types? (C#) 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