Support for serializing generic classes has been implemented.#96
Support for serializing generic classes has been implemented.#96gif-hara wants to merge 6 commits intomackysoft:mainfrom
Conversation
|
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. |
|
Hi @mackysoft . Thank you for considering my proposal! I would be very happy if you could consider adopting it once it stabilizes! |
Description
Support for generic classes such as the following has been added:
Changes made
MakeGenericTypefunction to generate the type.ignoreGenericTypeChecktoIntrinsicTypePolicy.IsAllowed, enabling the option to bypass evaluation ofIsGenericType.MakeGenericTypeis called.TypeMenuUtility.GetSplittedTypePath.TypeCandidateServiceno longer performs checks based onIIntrinsicTypePolicyandITypeCompatibilityPolicy.ITypeCandidateProvideralready performs this check, we determined this processing is unnecessary.