I created enum and set SerializeField to this field like this.
using UnityEngine;
public class Test : MonoBehaviour
{
[SerializeField] private TestEnum _segmentCode;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
}
public enum TestEnum
{
A, B, C
}
I can see TestEnum field in inspector.
But can not change this value and get error below.
NullReferenceException: Object reference not set to an instance of an object
UnityEditor.EditorGUI.DoTextField (UnityEditor.EditorGUI+RecycledTextEditor editor, System.Int32 id, UnityEngine.Rect position, System.String text, UnityEngine.GUIStyle style, System.String allowedletters, System.Boolean& changed, System.Boolean reset, System.Boolean multiline, System.Boolean passwordField, UnityEngine.GUIStyle cancelButtonStyle, System.Boolean checkTextLimit) (at /Users/bokken/build/output/unity/unity/Editor/Mono/EditorGUI.cs:1312)
UnityEditor.EditorGUI.DoTextField (UnityEditor.EditorGUI+RecycledTextEditor editor, System.Int32 id, UnityEngine.Rect position, System.String text, UnityEngine.GUIStyle style, System.String allowedletters, System.Boolean& changed, System.Boolean reset, System.Boolean multiline, System.Boolean passwordField) (at /Users/bokken/build/output/unity/unity/Editor/Mono/EditorGUI.cs:884)
UnityEditor.EditorGUI.TextFieldInternal (UnityEngine.Rect position, System.String text, UnityEngine.GUIStyle style) (at /Users/bokken/build/output/unity/unity/Editor/Mono/EditorGUI.cs:1794)
UnityEditor.EditorGUI.TextField (UnityEngine.Rect position, System.String text, UnityEngine.GUIStyle style) (at /Users/bokken/build/output/unity/unity/Editor/Mono/EditorGUI.cs:7887)
Sirenix.Utilities.Editor.SirenixEditorGUI.SearchField (UnityEngine.Rect rect, System.String searchText, System.Boolean forceFocus, System.String controlName) (at :0)
Sirenix.OdinInspector.Editor.OdinMenuTree.DrawSearchField (UnityEngine.Rect rect, System.String searchTerm, System.Boolean autoFocus) (at <5e70d1f2e2084cfa9fcd57f29a231480>:0)
Sirenix.OdinInspector.Editor.OdinMenuTree.DrawSearchToolbar (UnityEngine.GUIStyle toolbarStyle) (at <5e70d1f2e2084cfa9fcd57f29a231480>:0)
Sirenix.OdinInspector.Editor.OdinSelector1[T].DrawSelectionTree () (at <5e70d1f2e2084cfa9fcd57f29a231480>:0) System.Reflection.RuntimeMethodInfo.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[ ] parameters, System.Globalization.CultureInfo culture) (at <f78378fc25024256ba9c49776f5e810c>:0) UnityEngine.Debug:LogException(Exception) Sirenix.OdinInspector.Editor.ActionResolvers.ActionResolver:smile:oAction(Int32) Sirenix.OdinInspector.Editor.Drawers.OnInspectorGUIAttributeDrawer:smile:rawPropertyLayout(GUIContent) Sirenix.OdinInspector.Editor.OdinDrawer:smile:rawProperty(GUIContent) Sirenix.OdinInspector.Editor.InspectorProperty:smile:raw(GUIContent) Sirenix.OdinInspector.Editor.Drawers.CompositeDrawer:smile:rawPropertyLayout(GUIContent) Sirenix.OdinInspector.Editor.OdinDrawer:CallNextDrawer(GUIContent) Sirenix.OdinInspector.Editor.Drawers.FixUnityNullDrawer1:smile:rawPropertyLayout(GUIContent)
Sirenix.OdinInspector.Editor.OdinDrawer:CallNextDrawer(GUIContent)
Sirenix.OdinInspector.Editor.Drawers.ReferenceDrawer`1:smile:rawPropertyLayout(GUIContent)
Sirenix.OdinInspector.Editor.OdinDrawer:smile:rawProperty(GUIContent)
Sirenix.OdinInspector.Editor.InspectorProperty:smile:raw(GUIContent)
Sirenix.OdinInspector.Editor.PropertyTree:smile:rawProperties()
Sirenix.OdinInspector.Editor.PropertyTree:smile:raw(Boolean)
Sirenix.OdinInspector.Editor.OdinEditorWindow:smile:rawEditor(Int32)
Sirenix.OdinInspector.Editor.OdinEditorWindow:smile:rawEditors()
Sirenix.OdinInspector.Editor.OdinEditorWindow:OnGUI()
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&) (at /Users/bokken/build/output/unity/unity/Modules/IMGUI/GUIUtility.cs:189)
Unity version 2021.3.29f1
What happens??How can I fix it??
I can give additional information.
I created new project and I tried same thing.
It works.
So, this error on only my project…
but I can’t find what caused from.
Well the error is coming from Odin Inspector.
It was caused by Unity changing the name of a few GUIStyles, which broke a lot of editor tools.
Solution is to just update Odin.
spiney199:
Well the error is coming from Odin Inspector.
It was caused by Unity changing the game of a few GUIStyles, which broke a lot of editor tools.
Solution is to just update Odin.
Ah, I missed that!
Thank you! I’ll try update!
Fyi this has been fixed for Unity 6 in the new Odin release 3.3.1 (May 14th, 2024).