Combine two enums into one object (editable in dropdown of inspector)

I would like to know if combining these two dropdown enums would be possible? I.e. I would make a variable called defense then making a list of it. Defense would have the Type and Resistance inside the object.

7721395--969010--upload_2021-12-9_3-37-28.png

Make a struct. In here you can put multiple variables.
You can put [System.Serialize] in front of the struct and in your class simply add a variable array of the struct.

If you need further help let me know

2 Likes

ahh thats why there was no dropdown, i was close but didn’t know about the serialize part. Thank you!

7721530--969046--upload_2021-12-9_4-45-3.png
It seems like it’s serializing but it’s blank.

[System.Serializable]public struct Defense{
    Resistance resistance;
    Type type;
}
public Defense[] defense;

Put the struct above the class, not inside of the class. Do this for the enums as well. This way they are accessible everywhere

You are not serializing your fields. Also if that Type is from System.Type, you cannot serialize that one.

I’ve tried both in and outside of the class but no luck. Here is the full script.

using System.Collections;
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

[System.Serializable]
public enum Type{
    Fire,
    Ice,
    Elec,
    Force,
    Light,
    Dark,
    Heal,
    Buff,
    Ailment,
    Almighty,
}
[System.Serializable]
public enum Resistance{
    Weak,
    Resist,
    Null,
    Drain,
    Reflect,
}
[System.Serializable]
public struct Defense{
    Resistance resistance;
    Type type;
}

[CreateAssetMenu(menuName = "Scriptable Objects/Object")]
public class scriptObject : ScriptableObject
{
    public Defense defense;

    [Header("Profile")]
    public int hp;
    public int attack;
}

That has nothing to do with it. You are just not serializing your fields. You can have enums and classes anywhere.

I found out why it wasn’t working, I didn’t see the difference between serialize field and serializable

[Serializable]
public struct Defense{
    [SerializeField]
    Resistance resistance;
    [SerializeField]
    Type type;
}

Be careful about using the name ‘Type’ for your enum, because as soon as you put using System; in any bit of code that also uses your enum, it’s going to conflict with the System.Type class.

I’d suggest using a more descriptive name to avoid any future issues.

Will do thank you!