`[SaintsRow]` should supports `SerializeReference`
Closed this issue · 3 comments
I'm trying to use [SerializeReference]
with [ReferencePicker]
to render inspector for something similar to this
public interface IRefInterface { }
[Serializable]
public class RefClass: IRefInterface
{
[LayoutGroup("Base", ELayout.Horizontal)]
public int a;
public int b;
public int c;
}
// Usage
[SerializeReference, ReferencePicker]
public IRefInterface item;
Notice how I need a Layout
in the subclass. This doesn't work unless I use SaintsRow
.
[SerializeReference, ReferencePicker, SaintsRow]
public IRefInterface item;
Now layout renders correctly. Only if the reference is assigned.
When the reference is null SaintsRow drawer throw the following exception:
NullReferenceException: Object reference not set to an instance of an object
SaintsField.Editor.Utils.ReflectUtils.GetSelfAndBaseTypes (System.Object target) (at ./Library/PackageCache/today.comes.saintsfield@9d9f91f96f/Editor/Utils/ReflectUtils.cs:14)
SaintsField.Editor.SaintsEditor.GetRenderers (System.Collections.Generic.IReadOnlyDictionary`2[TKey,TValue] serializedPropertyDict, UnityEditor.SerializedObject serializedObject, System.Object target) (at ./Library/PackageCache/today.comes.saintsfield@9d9f91f96f/Editor/SaintsEditor.cs:241)
SaintsField.Editor.Playa.SaintsRowAttributeDrawer.CreatePropertyGUI (UnityEditor.SerializedProperty property) (at ./Library/PackageCache/today.comes.saintsfield@9d9f91f96f/Editor/Playa/SaintsRowAttributeDrawer.cs:179)
UnityEditor.UIElements.PropertyField.Reset (UnityEditor.SerializedProperty newProperty) (at <50e19b0ed93a4256b2e454b4acec2d48>:0)
UnityEditor.UIElements.PropertyField.Reset (UnityEditor.UIElements.SerializedPropertyBindEvent evt) (at <50e19b0ed93a4256b2e454b4acec2d48>:0)
UnityEditor.UIElements.PropertyField.ExecuteDefaultActionAtTarget (UnityEngine.UIElements.EventBase evt) (at <50e19b0ed93a4256b2e454b4acec2d48>:0)
UnityEngine.UIElements.CallbackEventHandler.HandleEvent (UnityEngine.UIElements.EventBase evt) (at <7ec34a9fe0b043f08800d3612cbf36c3>:0)
UnityEngine.UIElements.CallbackEventHandler.HandleEventAtCurrentTargetAndPhase (UnityEngine.UIElements.EventBase evt) (at <7ec34a9fe0b043f08800d3612cbf36c3>:0)
UnityEngine.UIElements.CallbackEventHandler.HandleEventAtTargetPhase (UnityEngine.UIElements.EventBase evt) (at <7ec34a9fe0b043f08800d3612cbf36c3>:0)
UnityEngine.UIElements.CallbackEventHandler.HandleEventAtTargetAndDefaultPhase (UnityEngine.UIElements.EventBase evt) (at <7ec34a9fe0b043f08800d3612cbf36c3>:0)
UnityEditor.UIElements.Bindings.SerializedObjectBindingContext.SendBindingEvent[TEventType] (TEventType evt, UnityEngine.UIElements.VisualElement target) (at <28a6e5fe38a74a678a32cfa433f4f24d>:0)
UnityEditor.UIElements.Bindings.SerializedObjectBindingContext.BindPropertyRelative (UnityEngine.UIElements.IBindable field, UnityEditor.SerializedProperty parentProperty) (at <28a6e5fe38a74a678a32cfa433f4f24d>:0)
UnityEditor.UIElements.Bindings.SerializedObjectBindingContext.BindTree (UnityEngine.UIElements.VisualElement element, UnityEditor.SerializedProperty parentProperty) (at <28a6e5fe38a74a678a32cfa433f4f24d>:0)
UnityEditor.UIElements.Bindings.SerializedObjectBindingContext.ContinueBinding (UnityEngine.UIElements.VisualElement element, UnityEditor.SerializedProperty parentProperty) (at <28a6e5fe38a74a678a32cfa433f4f24d>:0)
UnityEditor.UIElements.Bindings.SerializedObjectBindingContext.Bind (UnityEngine.UIElements.VisualElement element) (at <28a6e5fe38a74a678a32cfa433f4f24d>:0)
UnityEditor.UIElements.Bindings.DefaultSerializedObjectBindingImplementation.BindProperty (UnityEngine.UIElements.IBindable field, UnityEditor.SerializedObject obj) (at <28a6e5fe38a74a678a32cfa433f4f24d>:0)
UnityEditor.UIElements.BindingExtensions.BindProperty (UnityEngine.UIElements.IBindable field, UnityEditor.SerializedObject obj) (at <50e19b0ed93a4256b2e454b4acec2d48>:0)
SaintsField.Editor.Core.SaintsPropertyDrawer.OnAwakeUiToolKitInternal (UnityEditor.SerializedProperty property, UnityEngine.UIElements.VisualElement containerElement, System.Object parent, System.Collections.Generic.IReadOnlyList`1[T] saintsPropertyDrawers) (at ./Library/PackageCache/today.comes.saintsfield@9d9f91f96f/Editor/Core/SaintsPropertyDrawer.cs:1914)
SaintsField.Editor.Core.SaintsPropertyDrawer+<>c__DisplayClass38_0.<CreatePropertyGUI>b__2 () (at ./Library/PackageCache/today.comes.saintsfield@9d9f91f96f/Editor/Core/SaintsPropertyDrawer.cs:985)
UnityEngine.UIElements.VisualElement+SimpleScheduledItem.PerformTimerUpdate (UnityEngine.UIElements.TimerState state) (at <7ec34a9fe0b043f08800d3612cbf36c3>:0)
UnityEngine.UIElements.TimerEventScheduler.UpdateScheduledEvents () (at <7ec34a9fe0b043f08800d3612cbf36c3>:0)
UnityEngine.UIElements.UIElementsUtility.UnityEngine.UIElements.IUIElementsUtility.UpdateSchedulers () (at <7ec34a9fe0b043f08800d3612cbf36c3>:0)
UnityEngine.UIElements.UIEventRegistration.UpdateSchedulers () (at <7ec34a9fe0b043f08800d3612cbf36c3>:0)
UnityEditor.RetainedMode.UpdateSchedulers () (at <28a6e5fe38a74a678a32cfa433f4f24d>:0)
SaintsRow
does not work with SerializeReference
because it's designed to work with serialized field/property. SerializeReference
is internally draw by Unity (which is not the same process as serialized field/property) which does not expose drawing API for extending.
I'll see if it's possible to let SaintsRow
support it.
Hi,
this feature has been added in 3.4.11
using SaintsField;
public interface IRefInterface
{
public int TheInt { get; }
}
[Serializable]
public struct StructImpl : IRefInterface
{
[field: SerializeField]
public int TheInt { get; set; }
[LayoutStart("Hi", ELayout.FoldoutBox)]
public string myStruct;
public ClassDirect nestedClass;
}
[SerializeReference, ReferencePicker, SaintsRow]
public IRefInterface saints;
[SerializeReference, ReferencePicker(hideLabel: true), SaintsRow(inline: true)]
public IRefInterface inline;
Please note: if using together with ReferencePicker
, always put SaintsRow
after it
This is working great. Thank you