Custom class won't show up in inspector (serialization question)

Hi,

I have a class that stores two integers and a gameObject and I have an array of this class in another object that I need to see in inspector to set values in.

My custom class:

    public class LootDrop
    {
       public BaseCollectible Loot;
        public int Min;
        public int Max;
    }
}

and the other class is this (hence being abstract)

public class Crate : MonoBehaviour
{
    public LootDrop[] LootDrops;
}

Problem is I can’t see the fields of LootDrop in my Crate instances and I think it has to do with serialization and I can’t get my head around what’s the exact problem.

I’ve tried putting [Serializable] tag before my LootDrop class and SerializeField before the LootDrops in Crate class, doesn’t work.

Thanks

Make sure you have

[System.Serializable]

above your custom class

When you say you don’t see the fields, do you actually see the “LootDrops” array field? You have to increase the “size” field to actually add elements to the array. If your custom class has the System.Serializable attribute it should show up for the elements of your array. So make sure you saved all files and that you don’t have any compiler errors in your project (otherwise your changes can’t be applied since the project couldn’t be compiled).

If it still doesn’t work, make sure you don’t have a custom editor for your “Crate” class. A screenshot of the inspector showing a Crate instance might help.

Note that “BaseCollectible” sounds like you want to use inheritance here. Keep in mind that polymorphism / inheritance is not supported for custom serializable classes. Only classes derived from MonoBehaviour or ScriptableObject do support polymorphism. See script serialization for more details.