Vector2Int List not persisting in SerializedScriptableObject after Unity is closed and reopened, but a bool[,] array and other variables do persist fine.

Issue #773 closed
Brennon Williams created an issue

1. What happened?

I have a class derived from SerializedScriptable object that has a List of Vector2Ints. When I close and reopen Unity, other variables in the class like a string, Vector2Int, and a 2D bool array all persist just fine. Only this list of Vector2Ints doesn’t persist. After closing and reopening Unity, the list is empty.

[CreateAssetMenu(fileName = "Formation", menuName = "B/Formation")]
    public class Formation : SerializedScriptableObject
    {
        //No matter what, this List<Vector2Int> does not persist between sessions:
        private List<Vector2Int> orderedOffsets;
        //Its meant to be private, but for the sake of testing I also tried public & [ShowInInspector]:
        //[ShowInInspector] public List<Vector2Int> orderedOffsets;

        //The values of this bool[,] variable persist fine, though
        [BoxGroup("Formation")]
        [TableMatrix(DrawElementMethod = "DrawColoredEnumElement", ResizableColumns = false, SquareCells = true)]
        public bool[,] formationCellDrawing = new bool[16,16];

        //This Vector2Int also persists fine
        public Vector2Int startCell;

        //As does this string
        [ShowInInspector, TextArea(), HideLabel]
        private string orderedOffsetsJoined;

2. How can we reproduce it?

I’ve attached a zip of the class in question, as well as another class it uses (you can also just comment out OnEnable()).

3. If screenshots would help explain or demonstrate your issue, please include these.

Don’t think its necessary for this issue.

4. What version of Unity are you using?

2020.3.3f1

5. What version of Odin are you using? (See "Tools > Odin Inspector > About")

3.0.4.0

6. Do you have Editor Only mode enabled?

No.

7. What operating system are you on?

macOS Big Sur 11.2.3

Comments (3)

  1. Tor Esa Vestergaard

    I'm afraid this fails to reproduce; in your example scripts, the fields you expect to be serialized should not be serialized because they are not annotated correctly, or because Unity is serializing them. Note that if ShowInInspector is needed for a thing to be shown, it is not serialized.

    Please read through the serialization tutorials and use the serialization debugger to verify what the expected behaviour of Odin's serialization is in various cases such as this.

  2. Log in to comment