[MODERATOR NOTE]: this thread contains out of date information. modern unity versions can serialize struct
as long as they have the [System.Serializable]
attribute. However, serialization of interface
readonly struct
, record
, record struct
, readonly record struct
, Tuple
and ValueTuple
is still impossible within normal unity serialization.
Hello everyone,
I already spent a day trying to wrap my head around property serialization in Unity. I’m trying to create a custom inspector that lets me setup a list of actions that are carried out on specific input events.
The inspector works well and everything, but I cannot get it to survive the switch to Play mode, since I cannot figure out a way to structure the data in a way Unity can serialize.
Could anyone please have a look and give me a hint?
public class InputListener : InputReceiver
{
[System.Serializable]
public struct InputAction
{
public string actionName;
public float delay;
public bool objectState;
public bool componentState;
public Vector3 targetPosition;
public string sendMessage;
public AudioClip playAudio;
}
[System.Serializable]
public class InputActions
{
[SerializeField]
public List<InputAction>[] actions = new List<InputAction>[6];
}
}
I thought that wrapping a List in a member class helps Unity serialize it. But I canno get it to work. Please help!
PS: The thread tile is wrong, it’s a List of Lists of Struct I changed that while writing this post