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

Incorrect work of [ReferencePicker] with generic inheritance #112

Closed
dragon122 opened this issue Dec 17, 2024 · 3 comments
Closed

Incorrect work of [ReferencePicker] with generic inheritance #112

dragon122 opened this issue Dec 17, 2024 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@dragon122
Copy link

Same setup as in the ReferencePicker example except we move abstract classes to a parent script:
IllustrationA

Everything works well, but as soon as we make a generic version out of our classes-holders:

IllustrationB

Whenever the reference picker arrow is clicked, nothing happens and a NullRef exception is thrown pointing to the line 31 in "ReferencePickerAttributeDrawer" (I guess "realType" is null).
Interestingly, if we move only one abstract class to the ParentScript - everything will work as intended.

TylerTemp added a commit that referenced this issue Dec 18, 2024
@TylerTemp
Copy link
Owner

Hi,

Interesting, I believe this is a new feature from Unity that I didn't notice.

What's your Unity version?

When I test on 2022.3.14.f1, it shows nothing (no arrow picker at all) with a different error. The script is as you provided:

// ParentScript.cs
namespace SaintsField.Samples.Scripts.IssueAndTesting.Issue.Issue112
{
    public class ParentScript<T>: MonoBehaviour
    {
        [Serializable]
        public abstract class Base1Fruit { }

        [Serializable]
        public abstract class Base2Fruit: Base1Fruit { }
    }
}

// ChildScript.cs
namespace SaintsField.Samples.Scripts.IssueAndTesting.Issue.Issue112
{
    public class ChildScript: ParentScript<float>
    {
        [Serializable]
        public class Apple: Base2Fruit { }

        [Serializable]
        public class Orange: Base2Fruit { }

        [SerializeReference, ReferencePicker] public Base2Fruit item;
    }
}

Inspector:

image

Error:

image

The field ...ChildScript.item has the [SerializeReference] attribute applied, but is of type ....ParentScript.Base2Fruit<System.Single>, which is a generic instance type. This is not supported. You must create a non-generic subclass of your generic instance type and use that as the field type instead.

Removing ReferencePicker gives the same error, which means the error came from Unity rather than SaintsField.

So providing your unity version is appreciated.

@TylerTemp TylerTemp added the question Further information is requested label Dec 18, 2024
@dragon122
Copy link
Author

Tested on Unity 6000.0.25f1 and 6000.1.0a4 (SaintsField 3.9) with the same result.
Thanks

@TylerTemp TylerTemp added bug Something isn't working and removed question Further information is requested labels Dec 18, 2024
@TylerTemp TylerTemp self-assigned this Dec 18, 2024
@TylerTemp
Copy link
Owner

Hi

This bug has been fixed in 3.9.1, please have a try.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants