• 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
0
Question by ina · Jan 19, 2012 at 01:18 PM · runtimedataenum

Adding elements to an enum at runtime

Is it possible to add elements to an enum at runtime?

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

3 Replies

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

Answer by Owen-Reynolds · Jan 19, 2012 at 03:32 PM

Enums are almost always used to help read if/switch logic. Something like:

 enum doorType { open, closed, locked, broken, UNKNOWN };

 if(door1.status == doorType.locked) { 
   AddMessage("Locked"); PlaySound(knobJiggle); }
 else if(door1.status == doorType.closed) {
   door1.status=doorType.open; door1.animation.Play("opening"); }

If you wanted to add a new value, like gluedShut, you'd need to add new ifs to handle it, so adding at runtime wouldn't be very helpful. If you want something you can add to, try an array, List or Dictionary. Can then say things like myStuff.Add("hammer");

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 flamy · Jan 20, 2012 at 05:23 AM 0
Share

ya but you can also use enum as named constants... just saying ...

As i said even adding an enum at run time wont help a programmer..

avatar image zereda-games · Feb 15, 2019 at 01:11 PM 0
Share

here is is a good link on this sort of idea

https://stackoverflow.com/questions/2779743/can-you-add-to-an-enum-type-in-run-time

hope it helps.

avatar image
1

Answer by flamy · Jan 19, 2012 at 01:39 PM

simple answer is no... you can't do it

enum is jus like class or struct ... do u think it is possible to add a new member or function to a class at run time??

also enums are supposed to be a complete static enumeration. Even it is possible to do it... i dont think it is worth all the effort?!! Are u just trying out of ur intrest?!

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 larex39 · May 07, 2020 at 07:16 AM

Here is youtube tutorial how to show List as Enum in inspector alt text https://www.youtube.com/watch?v=ThcSHbVh7xc


gif.gif (253.9 kB)
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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

8 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to save run-time variables to dictionary? 1 Answer

Export objects to a .3DS file at runtime 1 Answer

Using raycast to sonify point cloud data and geometry of shapes 0 Answers

A List of functions to call - is there a better solution? 5 Answers

What to use to store data like eg. block types? 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