v0lt13 / EditorAttributes

EditorAttributes is a unity package that adds some extra editor attributes to your project to easily customize your editors without having to write any editor code.
https://editorattributesdocs.readthedocs.io/
The Unlicense
116 stars 9 forks source link

Various Fields not working in SerializeReference Structs #2

Closed christides11 closed 11 months ago

christides11 commented 11 months ago

currently doing

using UnityEngine;
public class Example : MonoBehaviour
{
    [SerializeReference] public IStateVar exampleVar = new ExampleVar();
}
public interface IStateVar { }
using EditorAttributes;

[System.Serializable]
public struct ExampleVar : IStateVar
{
    public bool shouldShow;

    public int intA;
    [ShowField(nameof(shouldShow))] 
    public int intB;
}

Produces this error

NullReferenceException: Object reference not set to an instance of an object
EditorAttributes.Editor.PropertyDrawerBase.GetConditionValue[T] (System.Reflection.MemberInfo memberInfo, UnityEngine.PropertyAttribute attribute, System.Object targetObject) (at ./Library/PackageCache/com.v0lt.editor-attributes@1d0830bab0/Scripts/Attributes/Editor/PropertyDrawerBase.cs:95)
EditorAttributes.Editor.ShowFieldDrawer.OnGUI (UnityEngine.Rect position, UnityEditor.SerializedProperty property, UnityEngine.GUIContent label) (at ./Library/PackageCache/com.v0lt.editor-attributes@1d0830bab0/Scripts/Attributes/Editor/ShowFieldDrawer.cs:16)
UnityEditor.PropertyDrawer.OnGUISafe (UnityEngine.Rect position, UnityEditor.SerializedProperty property, UnityEngine.GUIContent label) (at <7aeb7d7a52d04045b8a1c734633fa931>:0)
UnityEditor.PropertyHandler.OnGUI (UnityEngine.Rect position, UnityEditor.SerializedProperty property, UnityEngine.GUIContent label, System.Boolean includeChildren, UnityEngine.Rect visibleArea) (at <7aeb7d7a52d04045b8a1c734633fa931>:0)
UnityEditor.PropertyHandler.OnGUI (UnityEngine.Rect position, UnityEditor.SerializedProperty property, UnityEngine.GUIContent label, System.Boolean includeChildren) (at <7aeb7d7a52d04045b8a1c734633fa931>:0)
UnityEditor.PropertyHandler.OnGUI (UnityEngine.Rect position, UnityEditor.SerializedProperty property, UnityEngine.GUIContent label, System.Boolean includeChildren, UnityEngine.Rect visibleArea) (at <7aeb7d7a52d04045b8a1c734633fa931>:0)
UnityEditor.PropertyHandler.OnGUI (UnityEngine.Rect position, UnityEditor.SerializedProperty property, UnityEngine.GUIContent label, System.Boolean includeChildren) (at <7aeb7d7a52d04045b8a1c734633fa931>:0)
UnityEditor.PropertyHandler.OnGUILayout (UnityEditor.SerializedProperty property, UnityEngine.GUIContent label, System.Boolean includeChildren, UnityEngine.GUILayoutOption[] options) (at <7aeb7d7a52d04045b8a1c734633fa931>:0)
UnityEditor.EditorGUILayout.PropertyField (UnityEditor.SerializedProperty property, UnityEngine.GUIContent label, System.Boolean includeChildren, UnityEngine.GUILayoutOption[] options) (at <7aeb7d7a52d04045b8a1c734633fa931>:0)
UnityEditor.EditorGUILayout.PropertyField (UnityEditor.SerializedProperty property, System.Boolean includeChildren, UnityEngine.GUILayoutOption[] options) (at <7aeb7d7a52d04045b8a1c734633fa931>:0)
UnityEditor.Editor.DoDrawDefaultInspector (UnityEditor.SerializedObject obj) (at <7aeb7d7a52d04045b8a1c734633fa931>:0)
UnityEditor.Editor.DoDrawDefaultInspector () (at <7aeb7d7a52d04045b8a1c734633fa931>:0)
UnityEditor.Editor.DrawDefaultInspector () (at <7aeb7d7a52d04045b8a1c734633fa931>:0)
EditorAttributes.Editor.EditorExtension.OnInspectorGUI () (at ./Library/PackageCache/com.v0lt.editor-attributes@1d0830bab0/Scripts/Attributes/Editor/EditorExtension.cs:42)
UnityEditor.UIElements.InspectorElement+<>c__DisplayClass72_0.<CreateInspectorElementUsingIMGUI>b__0 () (at <7aeb7d7a52d04045b8a1c734633fa931>:0)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&)

This seems to happen with any field that ask for the name of a condition (ShowField, HideField, ConditionalField, DisableField, etc).

v0lt13 commented 11 months ago

Thanks for reporting this, it will be fixed in the next update