Skip to content

Commit 72d6102

Browse files
fix: compile error with generic NetworkBehaviour singletons (#2603)
* fix: compile error with generic NetworkBehaviour singletons * changelog * Added another fix for a similar issue. --------- Co-authored-by: Noel Stephens <noel.stephens@unity3d.com>
1 parent 208d1c9 commit 72d6102

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

com.unity.netcode.gameobjects/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Additional documentation and release notes are available at [Multiplayer Documen
1616
- Fixed issue where `NetworkObject.SpawnWithObservers` was not being honored for late joining clients. (#2623)
1717
- Fixed issue where invoking `NetworkManager.Shutdown` multiple times, depending upon the timing, could cause an exception. (#2622)
1818
- Fixed issue where removing ownership would not notify the server that it gained ownership. This also resolves the issue where an owner authoritative NetworkTransform would not properly initialize upon removing ownership from a remote client. (#2618)
19+
- Fixed an ILPP compile error when creating a generic NetworkBehaviour singleton with a static T instance. (#2603)
1920

2021
### Changed
2122

com.unity.netcode.gameobjects/Editor/CodeGen/CodeGenHelpers.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public static uint Hash(this MethodDefinition methodDefinition)
5959

6060
public static bool IsSubclassOf(this TypeDefinition typeDefinition, string classTypeFullName)
6161
{
62-
if (!typeDefinition.IsClass)
62+
if (typeDefinition == null || !typeDefinition.IsClass)
6363
{
6464
return false;
6565
}
@@ -154,6 +154,10 @@ public static MethodReference MakeGeneric(this MethodReference self, params Type
154154

155155
public static bool IsSubclassOf(this TypeReference typeReference, TypeReference baseClass)
156156
{
157+
if (typeReference == null)
158+
{
159+
return false;
160+
}
157161
var type = typeReference.Resolve();
158162
if (type?.BaseType == null || type.BaseType.Name == nameof(Object))
159163
{

com.unity.netcode.gameobjects/Editor/CodeGen/NetworkBehaviourILPP.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2225,6 +2225,12 @@ private void GenerateVariableInitialization(TypeDefinition type)
22252225
}
22262226
field = new FieldReference(fieldDefinition.Name, fieldDefinition.FieldType, genericType);
22272227
}
2228+
2229+
if (field.FieldType.Resolve() == null)
2230+
{
2231+
continue;
2232+
}
2233+
22282234
if (!field.FieldType.IsArray && !field.FieldType.Resolve().IsArray && field.FieldType.IsSubclassOf(m_NetworkVariableBase_TypeRef))
22292235
{
22302236
// if({variable} == null) {

0 commit comments

Comments
 (0)