- Home /
Set default length for an array of elements of a custom class in inspector
I'm making a game set on a five-lane road and I want to create a scriptable object that can be used to rapidly create new patterns of traffic.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[CreateAssetMenu(fileName = "New Vehicle Set", menuName = "ScriptableObjects/Vehicle Set", order = 1)]
public class VehicleSet : ScriptableObject
{
public enum VehicleType {none, car, truck, coin}
[System.Serializable]
public class VehicleRow
{
public VehicleType[] rowVehicles = new VehicleType[5];
public int[] test = new int[5];
public VehicleRow()
{
rowVehicles = new VehicleType[5];
for (int i = 0;i<5;i++)
{
rowVehicles[i] = VehicleType.none;
}
}
}
public VehicleRow[] vehicles;
}
Right now, when i create a new instance of VehicleSet, it shows me the list of VehicleRows (which is initially empty) and i can add new rows.
While the int array initializes correctly with 5 elements, the VehicleType one is initially empty. How do I instruct the editor to initialize the array with a length of 5?
Your answer
Follow this Question
Related Questions
Confused about custom GameObjects,Custom GameObject confusion 0 Answers
Array of a custom class giving an error 1 Answer
NullReferenceException: but I have checked that there is a object and have a if(obj != null) before 0 Answers
Creating an instance of a ScriptableObject, that will not change the base asset. 2 Answers