Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 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 /
avatar image
3
Question by RatStory · Jun 18, 2013 at 06:48 PM · editorinspectorenum

Restrict which types of an Enum can be selected in inspector.

If you have an exposed scrip variable in the inspector that has an enum as its type, Unity provides a nice little drop down menu to let you choose from the types contained in the enum.

Is there a way to control which of those are visible/a user can select?

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

6 Replies

· Add your reply
  • Sort: 
avatar image
4

Answer by aka3eka · Sep 28, 2021 at 03:30 PM

This might be old but it still might be helpful for somebody. Use InspectorName attribute with empty string:

 enum MyEnum
 {
   [InspectorName(null)]
   HiddenValue,

   Value1,

   Value2
 }
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
1

Answer by KazYamof · Nov 26, 2018 at 11:45 AM

Just ressurecting the post in case of someone needs: I've made a slightly different approach.

First, I've created a custom enum with the values I wanted to show.

Then, each value of my custom enum receites the value of the Unity Enum type I want to set. Then, I only need to cast to the Unity Enum Type to set the value to object.

See the example with an Input Field

 //That's my custom enum. Only exposes 2 types of numeric values
 public enum CustomInputType
     {
         Integer = InputField.ContentType.IntegerNumber,
         Decimal = InputField.ContentType.DecimalNumber
     }
 
 //That's the cast I do to set the content type on my InputField
 this.inputField.contentType = (InputField.ContentType) this.CustomInputType;
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 roojerry · Jun 18, 2013 at 06:55 PM

I would look into creating a custom property drawer that ignores specified values.

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 RatStory · Jun 18, 2013 at 07:43 PM 0
Share

Having a bit of trouble figuring out how I'd go about telling it what values of the enum to ignore, how do I access the inside of the enum like that? I've used property drawers before, but I don't have a great grasp of them.

I feel like the answer will have to do with some sort of mask (given the nature of enums), but I'm really at a loss.

avatar image
0

Answer by Salim · Aug 16, 2018 at 11:06 PM

Why not create 2 Enum, one public that only have the values you want exposed in the inspector, and another one private that you use in your script. At Start() you can changes the private version based what is in the public instance with IF statements.

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 Thibaut_M · Sep 30, 2021 at 12:28 PM

Use the attribute [UnityEngine.HideInInspector] above the entry of your enum you want to hide. ,Use the attribute [UnityEngine.HideInInspector] above the entry you want to hide.

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 aka3eka · Oct 04, 2021 at 07:55 AM 0
Share

AFAIK this is only allowed for fields and doesn't help much with enum values.

  • 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

20 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

Related Questions

Exposing Enums in Custom Inspector 1 Answer

DropDownList with string array in Editor Inspector 5 Answers

EditorGUI Enum help 1 Answer

Draw specific Object Inspector into Rect 1 Answer

Way to graphically visualize a Vector2 or Vector3 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