Skip to content

Conversation

@gif-hara
Copy link

Description

レコーディング 2026-01-22 151951

Support for generic classes such as the following has been added:

public interface IObjectHolder<T> { }

[Serializable]
public sealed class ObjectHolder<T> : IObjectHolder<T> { }

[Serializable]
public sealed class ParticleSystemHolder : IObjectHolder<ParticleSystem> { }

public sealed class Test : MonoBehaviour
{
    // The following items are listed in the dropdown menu:
    // - ObjectHolder
    [SerializeReference, SubclassSelector]
    private IObjectHolder<GameObject> gameObjectHolder;

    // The following items are listed in the dropdown menu:
    // - ObjectHolder
    // - ParticleSystemHolder
    [SerializeReference, SubclassSelector]
    private IObjectHolder<ParticleSystem> particleSystemHolder;
}

Changes made

  • When searching for a target type that is a GenericType, we now use the MakeGenericType function to generate the type.
  • Added ignoreGenericTypeCheck to IntrinsicTypePolicy.IsAllowed, enabling the option to bypass evaluation of IsGenericType .
    • This flag is set to true only when MakeGenericType is called.
  • When the Type was a generic type, the dropdown menu did not display correctly, so I fixed TypeMenuUtility.GetSplittedTypePath .
  • TypeCandidateService no longer performs checks based on IIntrinsicTypePolicy and ITypeCompatibilityPolicy .
    • Because ITypeCandidateProvider already performs this check, we determined this processing is unnecessary.

@mackysoft
Copy link
Owner

Hi @gif-hara , thanks for the proposal and the detailed work.

During the 1.7.0 development cycle we did prototype support for constructed generic types in the SubclassSelector pipeline. However, we decided to drop it before the release because the behavior is still not stable enough across Unity versions and real projects (edge cases around serialization/deserialization, type resolution, and editor-side stability).

Because this package don’t want to ship a feature that can behave inconsistently depending on Unity patch level or project setup. Until Unity’s SerializeReference support for constructed generics becomes reliably stable, we will not add official support for using constructed generic types “as-is”.

For now, the recommended approach is to use a non-generic wrapper / derived type and serialize that instead.

[Serializable]
public class ParticleSystemHolder : ObjectHolder<ParticleSystem> { }

// Field type stays non-generic or uses the wrapper type
[SerializeReference, SubclassSelector]
private IObjectHolder<ParticleSystem> holder;

I can revisit native generic support once Unity’s behavior is consistent enough to provide a stable user experience. In the meantime, changes that rely on raw generic SerializeReference usage are likely to be rejected or kept behind an explicit experimental flag, to avoid regressions for the baseline support range.

@mackysoft mackysoft closed this Jan 22, 2026
@gif-hara
Copy link
Author

Hi @mackysoft . Thank you for considering my proposal! I would be very happy if you could consider adopting it once it stabilizes!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants