C# use gameobject[] inside a nested class

Hello everyones !
I am currently trying to write a script that instantiate biomes wich are nested class. Each biome have some GameObject[ ] that represent the differents assets who will be instantiated on my terrain.
So far my class look like this :

    [SerializeField]
    public class Forest
    {
        public GameObject[] Trees;
        public GameObject[] Bushes;
        public GameObject[] Rocks;

        public float TreeAmount = 2.0F;
        public float TreeRange = 10.0F;
        public float TreeSize = 2.0F;

        public float BushesAmount = 2.0F;
        public float BushesRange = 10.0F;
        public float BushesSize = 1.0F;

        public float RockAmount = 2.0F;
        public float RockRange = 10.0F;
        public float RockSize = 1.0F;
        public float BiggestRock = 50.0F;
        public float SmallestRock = 5.0F;
        public float RockSizeSteps = 10.0F;

        private GameObject[] TreeCollector;
        private Vector3 TreeData;
        private Vector3 RockData;
        private Vector3 AllRocksData;
        private Vector3 BushesData;

        public Forest()
        {
            TreeCollector = new GameObject[1000];
            TreeData = new Vector3(TreeAmount, TreeRange, TreeSize);
            RockData = new Vector3(RockAmount, RockRange, RockSize);
            AllRocksData = new Vector3(BiggestRock, SmallestRock, RockSizeSteps);
            BushesData = new Vector3(BushesAmount, BushesRange, BushesSize);
        }

        public void InstatiateForest()
        {
            InstantiateTrees(Trees, TreeData, TreeCollector);
            InstantiateRocks(Rocks, RockData, AllRocksData);
            FinishTreeInstantiation(TreeCollector);
        }
    }

I want to know how to fill the differents public variable of my class Forest from the inspector.
Is that possible ? Should i create another GameObject[ ] inside my script and pass it to my constructor for each GameObject[ ] in my class Forest ?

Thanks !

You could create a list of of the Forest class :

using System.Collections.Generic;

[System.Serializable]
public class Forest
{
...
}

public List<Forest> forest = new List<Forest>();

You should be able to fill in the vars from the inspector now.

There’s probably a better way of doing this though.

First of all, a class can not be serialized using [SerializeField]. It has to be [Serializable] or [System.Serializable].

You have two options to configure the fields in the inspector, you can make the forest being a part of a class that inherits either MonoBehaviour or ScriptableObject. This will make it visible in the inspector.

As said, replace SerializeField with Serializeable (from the System namespace).

To be able to edit the value of a field in the inspector, the field must be of a type that’s Serializeable, or an Array/List of a serializeable type.

As for everything that’s supposed to be serialized by Unity, don’t use constructors, as those will be called a lot during serialization. Instead, move that logic to an Instantiate method, and call that into the containing object’s Awake. So your Forest() constructor should be ditched, and you should create your data inside of InstantiateForest method,

Note that polymorphism does not work with Unity’s serialization - so you won’t be able to store a subclass of Forest in a field that’s of the type Forest.