So let’s say I have the Building
class, which inherits from ScriptableObject
. I want to have a way to give an indefinite amount of ‘components’ to objects of the Building
type. My approach is to have an abstract class BuildingComponent
, which is the parent of all component types such as Employer
if the building needs workers or Farm
if the building grows food. (e.g. a basic farm that needs workers and grows food would have both of those components, but an automatic farm wouldn’t have the Employer component.)
Right now Building
has a list of BuildingComponent
s, but I want to be able to populate that list when designing a scripted object of it.
I have it as follows:
[CreateAssetMenu]
public class Building : ScriptableObject
{
[SerializeField]
List<BuildingComponent> components;
}
[System.Serializable]
public abstract class BuildingComponent
{
}
[System.Serializable]
public class Mine_BuildingComp : BuildingComponent
{
}
When creating a Building
asset, it’s just blank. It doesn’t show the list in the editor, despite being labeled with [SerializeField] and both BuildingComponent
and Mine_BuildingComp
being labeled [System.Serializable].