Properties with [TypeFilter] attribute cannot instantiate in Inspector

Issue #782 resolved
Nicholas Aitken created an issue

What Happened: I think the [TypeFilter] attribute is broken. I have been using it for a long time successfully to limit the list of types for a property in the inspector. Just recently my properties with the [TypeFilter] attribute show the filtered list of object types, but selecting any of them always returns null.

Notably - reverting ODIN from 3.0.5 to 3.0.4 solves the problem. So the bug was introduced in the 3.0.5 update.

How to Reproduce:

Code and Screenshot GIF below. Notice that the myType property draws a drop-down in the Inspector with only the types dictated by the [TypeFilter] attribute (GOOD), BUT selecting any of these types only sets the property to null (BAD). They will not instantiate.

using System;
using System.Collections.Generic;
using Sirenix.OdinInspector;
using UnityEngine;

public class Test : SerializedMonoBehaviour
    [TypeFilter(nameof(GetCompatibleTypes))] [SerializeField]
    private IMyType myType;

    private IEnumerable<Type> GetCompatibleTypes()
        return new [] {typeof(MyTypeA), typeof(MyTypeB)};

public interface IMyType
{ }

public class MyTypeA : IMyType
{ }

public class MyTypeB : IMyType
{ }

public class MyTypeC : IMyType
{ }

Unity Version: 2021.1.5f1

ODIN Version:

Operating System: Windows 10

Comments (4)

  1. Tor Esa Vestergaard

    Fixed for patch 3.0.6. Thanks for reporting this! If you'd like to try out the fix, please contact me on Discord and I'll get you a preview build.

  2. Log in to comment