URGENT: "ArgumentException" and "Unity-backed value is null" errors on Scriptable Object asset that's not using Odin in-code

Issue #743 resolved
Brennon Williams created an issue

I’m using Unity 2020.1.5f and Odin 3.0.3.0 on a MacbookPro on OSX Catalina 10.15.6. The problem persists with Editor Only mode enabled and disabled.

I’m baffled as to why I’m getting these errors, especially since having AnimationState fields in a different Monobehavior is working fine.

Here is the first error:

Unity-backed value is null. This should already be fixed by the FixUnityNullDrawer!
UnityEngine.Debug:LogError(Object)
Sirenix.OdinInspector.Editor.Drawers.NullableReferenceDrawer`1:DrawPropertyLayout(GUIContent) (at X:/Repositories/sirenix-development/Sirenix Solution/Sirenix.OdinInspector.Editor/Drawers/Misc Drawers/NullableReferenceDrawer.cs:89)
Sirenix.OdinInspector.Editor.OdinDrawer:CallNextDrawer(GUIContent) (at X:/Repositories/sirenix-development/Sirenix Solution/Sirenix.OdinInspector.Editor/Drawers/OdinDrawer.cs:155)
Sirenix.OdinInspector.Editor.Drawers.FixUnityNullDrawer`1:DrawPropertyLayout(GUIContent) (at X:/Repositories/sirenix-development/Sirenix Solution/Sirenix.OdinInspector.Editor/Drawers/Misc Drawers/FixUnityNullDrawer.cs:78)
Sirenix.OdinInspector.Editor.OdinDrawer:CallNextDrawer(GUIContent) (at X:/Repositories/sirenix-development/Sirenix Solution/Sirenix.OdinInspector.Editor/Drawers/OdinDrawer.cs:155)
Sirenix.OdinInspector.Editor.Drawers.ReferenceDrawer`1:DrawPropertyLayout(GUIContent) (at X:/Repositories/sirenix-development/Sirenix Solution/Sirenix.OdinInspector.Editor/Drawers/Misc Drawers/ReferenceDrawer.cs:118)
Sirenix.OdinInspector.Editor.OdinDrawer:CallNextDrawer(GUIContent) (at X:/Repositories/sirenix-development/Sirenix Solution/Sirenix.OdinInspector.Editor/Drawers/OdinDrawer.cs:155)
Sirenix.OdinInspector.Editor.Drawers.PropertyContextMenuDrawer`1:DrawPropertyLayout(GUIContent) (at X:/Repositories/sirenix-development/Sirenix Solution/Sirenix.OdinInspector.Editor/Drawers/Misc Drawers/PropertyContextMenuDrawer.cs:653)
Sirenix.OdinInspector.Editor.OdinDrawer:DrawProperty(GUIContent) (at X:/Repositories/sirenix-development/Sirenix Solution/Sirenix.OdinInspector.Editor/Drawers/OdinDrawer.cs:109)
Sirenix.OdinInspector.Editor.InspectorProperty:Draw(GUIContent) (at X:/Repositories/sirenix-development/Sirenix Solution/Sirenix.OdinInspector.Editor/Core/InspectorProperty.cs:789)
Sirenix.OdinInspector.Editor.InspectorProperty:Draw() (at X:/Repositories/sirenix-development/Sirenix Solution/Sirenix.OdinInspector.Editor/Core/InspectorProperty.cs:677)
Sirenix.OdinInspector.Editor.Drawers.UnityObjectRootDrawer`1:DrawPropertyLayout(GUIContent) (at X:/Repositories/sirenix-development/Sirenix Solution/Sirenix.OdinInspector.Editor/Drawers/Value Drawers/UnityObjectRootDrawer.cs:60)
Sirenix.OdinInspector.Editor.OdinDrawer:DrawProperty(GUIContent) (at X:/Repositories/sirenix-development/Sirenix Solution/Sirenix.OdinInspector.Editor/Drawers/OdinDrawer.cs:109)
Sirenix.OdinInspector.Editor.InspectorProperty:Draw(GUIContent) (at X:/Repositories/sirenix-development/Sirenix Solution/Sirenix.OdinInspector.Editor/Core/InspectorProperty.cs:789)
Sirenix.OdinInspector.Editor.PropertyTree:DrawProperties() (at X:/Repositories/sirenix-development/Sirenix Solution/Sirenix.OdinInspector.Editor/Core/PropertyTree.cs:485)
Sirenix.OdinInspector.Editor.PropertyTree:Draw(Boolean) (at X:/Repositories/sirenix-development/Sirenix Solution/Sirenix.OdinInspector.Editor/Core/PropertyTree.cs:389)
Sirenix.OdinInspector.Editor.OdinEditor:DrawTree() (at X:/Repositories/sirenix-development/Sirenix Solution/Sirenix.OdinInspector.Editor/Drawers/OdinEditor.cs:93)
Sirenix.OdinInspector.Editor.OdinEditor:DrawOdinInspector() (at X:/Repositories/sirenix-development/Sirenix Solution/Sirenix.OdinInspector.Editor/Drawers/OdinEditor.cs:216)
Sirenix.OdinInspector.Editor.OdinEditor:OnInspectorGUI() (at X:/Repositories/sirenix-development/Sirenix Solution/Sirenix.OdinInspector.Editor/Drawers/OdinEditor.cs:85)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&) (at /Users/bokken/buildslave/unity/build/Modules/IMGUI/GUIUtility.cs:189)

And the second error:

ArgumentException: Getting control 2's position in a group with only 2 controls when doing repaint
Aborting
UnityEngine.GUILayoutGroup.GetNext () (at /Users/bokken/buildslave/unity/build/Modules/IMGUI/LayoutGroup.cs:129)
UnityEngine.GUILayoutUtility.DoGetRect (System.Single minWidth, System.Single maxWidth, System.Single minHeight, System.Single maxHeight, UnityEngine.GUIStyle style, UnityEngine.GUILayoutOption[] options) (at /Users/bokken/buildslave/unity/build/Modules/IMGUI/GUILayoutUtility.cs:464)
UnityEngine.GUILayoutUtility.GetRect (System.Single minWidth, System.Single maxWidth, System.Single minHeight, System.Single maxHeight, UnityEngine.GUIStyle style, UnityEngine.GUILayoutOption[] options) (at /Users/bokken/buildslave/unity/build/Modules/IMGUI/GUILayoutUtility.cs:453)
UnityEditor.EditorGUILayout.GetControlRect (System.Boolean hasLabel, System.Single height, UnityEngine.GUIStyle style, UnityEngine.GUILayoutOption[] options) (at /Users/bokken/buildslave/unity/build/Editor/Mono/EditorGUI.cs:10034)
UnityEditor.EditorGUILayout.GetControlRect (System.Boolean hasLabel, UnityEngine.GUILayoutOption[] options) (at /Users/bokken/buildslave/unity/build/Editor/Mono/EditorGUI.cs:10024)
Sirenix.Utilities.Editor.SirenixEditorGUI.GetFeatureRichControlRect (UnityEngine.GUIContent label, System.Int32 height, System.Int32& controlId, System.Boolean& hasKeyboardFocus, UnityEngine.Rect& valueRect, UnityEngine.GUILayoutOption[] options) (at X:/Repositories/sirenix-development/Sirenix Solution/Sirenix.Utilities.Editor/GUI/SirenixEditorGUI.cs:3159)
Sirenix.Utilities.Editor.SirenixEditorGUI.GetFeatureRichControlRect (UnityEngine.GUIContent label, System.Int32& controlId, System.Boolean& hasKeyboardFocus, UnityEngine.Rect& valueRect, UnityEngine.GUILayoutOption[] options) (at X:/Repositories/sirenix-development/Sirenix Solution/Sirenix.Utilities.Editor/GUI/SirenixEditorGUI.cs:3147)
Sirenix.OdinInspector.Editor.Drawers.NullableReferenceDrawer`1[T].DrawField (UnityEngine.GUIContent label) (at X:/Repositories/sirenix-development/Sirenix Solution/Sirenix.OdinInspector.Editor/Drawers/Misc Drawers/NullableReferenceDrawer.cs:155)
Sirenix.OdinInspector.Editor.Drawers.NullableReferenceDrawer`1[T].DrawPropertyLayout (UnityEngine.GUIContent label) (at X:/Repositories/sirenix-development/Sirenix Solution/Sirenix.OdinInspector.Editor/Drawers/Misc Drawers/NullableReferenceDrawer.cs:93)
Sirenix.OdinInspector.Editor.OdinDrawer.CallNextDrawer (UnityEngine.GUIContent label) (at X:/Repositories/sirenix-development/Sirenix Solution/Sirenix.OdinInspector.Editor/Drawers/OdinDrawer.cs:155)
Sirenix.OdinInspector.Editor.Drawers.FixUnityNullDrawer`1[T].DrawPropertyLayout (UnityEngine.GUIContent label) (at X:/Repositories/sirenix-development/Sirenix Solution/Sirenix.OdinInspector.Editor/Drawers/Misc Drawers/FixUnityNullDrawer.cs:78)
Sirenix.OdinInspector.Editor.OdinDrawer.CallNextDrawer (UnityEngine.GUIContent label) (at X:/Repositories/sirenix-development/Sirenix Solution/Sirenix.OdinInspector.Editor/Drawers/OdinDrawer.cs:155)
Sirenix.OdinInspector.Editor.Drawers.ReferenceDrawer`1[T].DrawPropertyLayout (UnityEngine.GUIContent label) (at X:/Repositories/sirenix-development/Sirenix Solution/Sirenix.OdinInspector.Editor/Drawers/Misc Drawers/ReferenceDrawer.cs:118)
Sirenix.OdinInspector.Editor.OdinDrawer.CallNextDrawer (UnityEngine.GUIContent label) (at X:/Repositories/sirenix-development/Sirenix Solution/Sirenix.OdinInspector.Editor/Drawers/OdinDrawer.cs:155)
Sirenix.OdinInspector.Editor.Drawers.PropertyContextMenuDrawer`1[T].DrawPropertyLayout (UnityEngine.GUIContent label) (at X:/Repositories/sirenix-development/Sirenix Solution/Sirenix.OdinInspector.Editor/Drawers/Misc Drawers/PropertyContextMenuDrawer.cs:653)
Sirenix.OdinInspector.Editor.OdinDrawer.DrawProperty (UnityEngine.GUIContent label) (at X:/Repositories/sirenix-development/Sirenix Solution/Sirenix.OdinInspector.Editor/Drawers/OdinDrawer.cs:109)
Sirenix.OdinInspector.Editor.InspectorProperty.Draw (UnityEngine.GUIContent defaultLabel) (at X:/Repositories/sirenix-development/Sirenix Solution/Sirenix.OdinInspector.Editor/Core/InspectorProperty.cs:789)
Rethrow as OdinPropertyException: This error occurred while being drawn by Odin.
Current IMGUI event: repaint
Odin Property Path: nextState
Odin Drawer Chain:
> PropertyContextMenuDrawer<AnimationState>
> ReferenceDrawer<AnimationState>
> FixUnityNullDrawer<AnimationState>
> NullableReferenceDrawer<AnimationState>
> CompositeDrawer.
UnityEngine.Debug:LogException(Exception)
Sirenix.OdinInspector.Editor.InspectorProperty:Draw(GUIContent) (at X:/Repositories/sirenix-development/Sirenix Solution/Sirenix.OdinInspector.Editor/Core/InspectorProperty.cs:866)
Sirenix.OdinInspector.Editor.InspectorProperty:Draw() (at X:/Repositories/sirenix-development/Sirenix Solution/Sirenix.OdinInspector.Editor/Core/InspectorProperty.cs:677)
Sirenix.OdinInspector.Editor.Drawers.UnityObjectRootDrawer`1:DrawPropertyLayout(GUIContent) (at X:/Repositories/sirenix-development/Sirenix Solution/Sirenix.OdinInspector.Editor/Drawers/Value Drawers/UnityObjectRootDrawer.cs:60)
Sirenix.OdinInspector.Editor.OdinDrawer:DrawProperty(GUIContent) (at X:/Repositories/sirenix-development/Sirenix Solution/Sirenix.OdinInspector.Editor/Drawers/OdinDrawer.cs:109)
Sirenix.OdinInspector.Editor.InspectorProperty:Draw(GUIContent) (at X:/Repositories/sirenix-development/Sirenix Solution/Sirenix.OdinInspector.Editor/Core/InspectorProperty.cs:789)
Sirenix.OdinInspector.Editor.PropertyTree:DrawProperties() (at X:/Repositories/sirenix-development/Sirenix Solution/Sirenix.OdinInspector.Editor/Core/PropertyTree.cs:485)
Sirenix.OdinInspector.Editor.PropertyTree:Draw(Boolean) (at X:/Repositories/sirenix-development/Sirenix Solution/Sirenix.OdinInspector.Editor/Core/PropertyTree.cs:389)
Sirenix.OdinInspector.Editor.OdinEditor:DrawTree() (at X:/Repositories/sirenix-development/Sirenix Solution/Sirenix.OdinInspector.Editor/Drawers/OdinEditor.cs:93)
Sirenix.OdinInspector.Editor.OdinEditor:DrawOdinInspector() (at X:/Repositories/sirenix-development/Sirenix Solution/Sirenix.OdinInspector.Editor/Drawers/OdinEditor.cs:216)
Sirenix.OdinInspector.Editor.OdinEditor:OnInspectorGUI() (at X:/Repositories/sirenix-development/Sirenix Solution/Sirenix.OdinInspector.Editor/Drawers/OdinEditor.cs:85)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&) (at /Users/bokken/buildslave/unity/build/Modules/IMGUI/GUIUtility.cs:189)

These errors appear when I create an asset from this scriptable object. Below is the most paired-down/simplified version of the class that still throws these errors:

using UnityEngine;

namespace AnimSM.Scripts.Actions
{
    [CreateAssetMenu(fileName = "ChangeState", menuName = "AnimSM/Change State")]
    public class ChangeStateAction : ScriptableObject
    {
        public int stateMachineId = 0;
        public AnimationState nextState;

        //This line also throws another ArgumentException error
        //[SerializeField] public List<AnimationState> ifInStates;  
    }
}

I’m confident that my code isn’t causing these problems, because the same ScriptableObject AnimationState is being referenced exactly the same way in the inspector of another ScriptableObject without any errors. Here’s a simplified version of the working version that doesn’t cause any errors:

namespace AnimSM.Scripts
{
    [CreateAssetMenu(fileName = "State Machine", menuName = "AnimSM/Animation State Machine")]
    public class AnimationStateMachine : ScriptableObject
    {
        public int machineId = 0;
        public string name;
        //None of this throws any errors, unlike the other ScriptableObject script
        public AnimationState startAnimationState;
        [SerializeField] public List<AnimationState> states;

        //...
    }
}

I could potentially email you guys a zip of the project, but its multiple Gigabytes. And again, it seems like this is an internal problem with Odin.

This issue is blocking my work so please respond as soon as possible.

Thanks.

Comments (4)

  1. Tor Esa Vestergaard

    I've investigated the issue and determined that Odin is incorrectly guessing that Unity is capable of serializing the AnimationState type (note that without Odin, the field is never shown at all regardless of where it is declared). I have added the UnityEngine.AnimationState type to the exclusion list of types that it looks like Unity can/will serialize, but that it actually cannot.

    The fix will be in patch 3.0.4, meanwhile a solution for you would be to put [HideInInspector] or [NonSerialized] on your AnimationState nextState field or otherwise indicate that it is not serialized and supposed to be inspected.

  2. Brennon Williams reporter

    Hi Tor,

    I think this issue is not resolved.

    To be clear, AnimationState is a class in my own namespace. I am not taking about UnityEngine.AnimationState. Here is the class:

    using UnityEngine;
    
    namespace AnimSM.Scripts.States
    {
        public abstract class AnimationState : ScriptableObject
        {
            protected int animatorLayer = 0;
            protected int machineNumber = 0;
    
            abstract public Color GizmoColor { get; }
    
            public virtual int Layer
            {
                get { return animatorLayer; }
                set { animatorLayer = value; }
            }
    
            //...
        }
    }
    

    As I mentioned, AnimationState is being referenced exactly the same way in the inspector of another ScriptableObject without any errors. So I have no idea why the AnimationState field in ChangeStateAction would throw these errors, but the exact same references in AnimationStateMachinedo not throw any errors (I put simplified versions of these scripts in my question.

  3. Tor Esa Vestergaard

    In your ChangeStateAction.cs script, the referenced type of the AnimationState nextState field is not AnimSM.Scripts.States.AnimationState, but UnityEngine.AnimationState. This is what is causing your issue.

  4. Brennon Williams reporter

    Ah, excellent catch, thank you! I’ve renamed my AnimationState class to avoid this kind of thing happening again.

  5. Log in to comment