List<> to enum (inspector)

Hi everyone,

  1. I have a game script with a serializable class called “Race” with name, strength etc.

  2. I then have: “public List raceList = new List();” which allows me to add new races in the inspector

  3. in the inspector I have created a few different races in the game script with their specific stats

  4. I now have a creature script where in the inspector I would like a drop down box (RaceEnum) listing those inspector created races

  5. on start the creature script Race will equal the raceEnum selected value (which should be a Race class)

I am having issues figuring out #4 I am assuming it should be something like this:

public enum RaceEnum{
      //get{gameScript.raceList.name}
     //OR
    //if I could somehow get a foreach(Race race in gameScript.raceList){
add race to RaceEnum
    ``} that would be nice
 }

could someone give me a hand???

Enums cannot be changed after the code is compiled - they’re constant values. It’s not possible to generate enums based on another structure.

If you want a drop down in the inspector based on a list of strings, write a custom inspector (check out the video tutorial or the docs), and use the EditorGUILayout.Popup method to generate the dropdown.