Skip to content

Commit

Permalink
fix: compile error with generic NetworkBehaviour singletons (#2603)
Browse files Browse the repository at this point in the history
* fix: compile error with generic NetworkBehaviour singletons

* changelog

* Added another fix for a similar issue.

---------

Co-authored-by: Noel Stephens <noel.stephens@unity3d.com>
  • Loading branch information
ShadauxCat and NoelStephensUnity authored Jul 18, 2023
1 parent 208d1c9 commit 72d6102
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions com.unity.netcode.gameobjects/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Additional documentation and release notes are available at [Multiplayer Documen
- Fixed issue where `NetworkObject.SpawnWithObservers` was not being honored for late joining clients. (#2623)
- Fixed issue where invoking `NetworkManager.Shutdown` multiple times, depending upon the timing, could cause an exception. (#2622)
- 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)
- Fixed an ILPP compile error when creating a generic NetworkBehaviour singleton with a static T instance. (#2603)

### Changed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public static uint Hash(this MethodDefinition methodDefinition)

public static bool IsSubclassOf(this TypeDefinition typeDefinition, string classTypeFullName)
{
if (!typeDefinition.IsClass)
if (typeDefinition == null || !typeDefinition.IsClass)
{
return false;
}
Expand Down Expand Up @@ -154,6 +154,10 @@ public static MethodReference MakeGeneric(this MethodReference self, params Type

public static bool IsSubclassOf(this TypeReference typeReference, TypeReference baseClass)
{
if (typeReference == null)
{
return false;
}
var type = typeReference.Resolve();
if (type?.BaseType == null || type.BaseType.Name == nameof(Object))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2225,6 +2225,12 @@ private void GenerateVariableInitialization(TypeDefinition type)
}
field = new FieldReference(fieldDefinition.Name, fieldDefinition.FieldType, genericType);
}

if (field.FieldType.Resolve() == null)
{
continue;
}

if (!field.FieldType.IsArray && !field.FieldType.Resolve().IsArray && field.FieldType.IsSubclassOf(m_NetworkVariableBase_TypeRef))
{
// if({variable} == null) {
Expand Down

0 comments on commit 72d6102

Please sign in to comment.