#Generic Serialization Issue

1 messages · Page 1 of 1 (latest)

sharp crown
#

Matrix_Map

[System.Serializable]
public struct Matrix_Map<Element>
{
    public Matrix_Row<Element>[] Matrix;
}

Matrix_Row

using UnityEngine;

[System.Serializable]
public struct Matrix_Row<Element>
{
    [SerializeField]
    public Element[] Elements;

    [HideInInspector]
    public int Length
    {
        get { return Elements.Length; }
        private set {; }
    }
}

I have this specific architecture for a system. The problem is that the Matrix_Row script's Elements property is not serialized in the inspector. I have a reason to believe that it is with the fact that the array is of a generic type.

What would be your guys recommended way too solve this, and also, seeing as such serialization issues seem to come up a lot of time(for example the lack of serialization for N-dimensional arrays, which is the reason of this slight inconvenient architecture in the first place), I wonder if there is a way too alter/add to engine/editor code to solve such problems. Thanks in advance.

#

As in "not serialized", it will not show up at all in the inspector.

#

<@&823670121133768714>

lethal magnet
#

Unity doesn't support this kind of generics. You'll need to make a concrete implementation of your serialized generic for it to work: ```cs
[Serializable]
public class GenBase<T>
{
[SerializeField] protected T[] elements;
}

public class FloatArr : GenBase<float> { }


Sadly, this also means that you can't use structs, as you need the inheritance.
sharp crown
#

Because this seems very inconvenient.

lethal magnet
#

I don't know of any.

sharp crown
#

Alright, thanks.