Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SaintsRow] should supports SerializeReference #80

Closed
alaa13212 opened this issue Aug 28, 2024 · 3 comments
Closed

[SaintsRow] should supports SerializeReference #80

alaa13212 opened this issue Aug 28, 2024 · 3 comments
Assignees
Labels
enhancement New feature or request

Comments

@alaa13212
Copy link

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)
@TylerTemp
Copy link
Owner

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.

@TylerTemp TylerTemp self-assigned this Aug 29, 2024
@TylerTemp TylerTemp added the enhancement New feature or request label Aug 29, 2024
@TylerTemp TylerTemp changed the title Null value of serialized fields is not accouned for in SaintsRow drawer [SaintsRow] should supports SerializeReference Aug 29, 2024
TylerTemp added a commit that referenced this issue Nov 11, 2024
@TylerTemp
Copy link
Owner

TylerTemp commented Nov 11, 2024

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;

image

Please note: if using together with ReferencePicker, always put SaintsRow after it

@alaa13212
Copy link
Author

This is working great. Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants