Skip to content

Commit 07c73ae

Browse files
committed
fix: Fixed incorrect concrete types used for creating generic scriptable objects
Concrete types that do not derive directly from the requested generic type were used to create a generic scriptable object. This behaviour was incorrect and an additional check was introduced that checks if the concrete type derives directly from the generic type.
1 parent a811147 commit 07c73ae

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

Runtime/Util/GenericTypesDatabase/GenericTypesDatabase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ private bool TryGetConcreteTypeImpl(Type genericType, out Type concreteType)
123123

124124
private bool TryGetEmptyDerivedType(Type genericType, out Type derivedType)
125125
{
126-
derivedType = TypeUtility.GetEmptyTypeDerivedFrom(genericType);
126+
derivedType = TypeUtility.GetEmptyTypeDerivedDirectlyFrom(genericType);
127127

128128
if (derivedType == null)
129129
return false;

Runtime/Util/TypeUtility.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,18 @@
1010

1111
internal static class TypeUtility
1212
{
13+
public static Type GetEmptyTypeDerivedDirectlyFrom(Type parentType)
14+
{
15+
#if UNITY_EDITOR
16+
return TypeCache.GetTypesDerivedFrom(parentType)
17+
.FirstOrDefault(type => type.IsEmpty() && type.BaseType == parentType);
18+
#else
19+
return parentType.Assembly.GetTypes()
20+
.Where(parentType.IsAssignableFrom)
21+
.FirstOrDefault(type => type.IsEmpty() && type.BaseType == parentType);
22+
#endif
23+
}
24+
1325
[CanBeNull]
1426
public static Type GetEmptyTypeDerivedFrom(Type parentType)
1527
{

0 commit comments

Comments
 (0)