- Home /
The question is answered, right answer was accepted
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.
If an answer helped and you have solved your issue, please accept an answer.
There's a better solution.
[System.Serializable]
public enum PieceType
{
Hero,
$$anonymous$$oveable,
Solid,
Empty
}
public PieceType pieceType;
You just need to make the enum serializable.
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?
Old post but for news: Don't use [Header] and it will work.
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;
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;
}
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.
it works thats the funny thing but if it does show error later on i will use your method
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.
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.
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
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