System.Object polymorphism with array and non-array types breaks the inspector

Issue #434 new
Nicolás Ezcurra
created an issue

Using Unity 2017.4.11f1 and Odin 2.0.5, when a field of type object, has it actual value changed while inspecting it, will break the inspector.

This behaviour occurs when the value types changes from an array type to a non array type, and vice versa.

Here is a simple component where this issue can be checked:

using UnityEngine;
using System.Collections;
using System.Collections.Generic;

using Sirenix.OdinInspector;
using System;

public class SimpleObjectFieldTest : SerializedMonoBehaviour 
{
    [SerializeField]
    public object field;


    [Button]
    public void SetInt()
    {
        field = default(int);
    }

    [Button]
    public void SetTransform()
    {
        field = transform;
    }

    [Button]
    public void SetFloatArray()
    {
        field = new float[0];
    }

    [Button]
    public void SetGameObjectArray()
    {
        field = new GameObject[0];
    }

    [Button]
    public void PrintType()
    {
        Debug.LogFormat("[ObjectFieldTest] Field type: {0}.", (field == null) ? "null" : field.GetType().ToString());
    }
}

I'm also attaching an attempt of solution using an Attribute (ObjectFieldTest, DrawAsTypeAttribute and DrawAsTypeAttributeDrawer).

Thanks for your time!

Comments (0)

  1. Log in to comment