From 8bed4951353f17ce825e6eb26363af6afe78d181 Mon Sep 17 00:00:00 2001 From: Kitty Draper Date: Thu, 29 Jun 2023 14:38:42 -0500 Subject: [PATCH 1/3] fix: compile error with generic NetworkBehaviour singletons --- .../Editor/CodeGen/CodeGenHelpers.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/com.unity.netcode.gameobjects/Editor/CodeGen/CodeGenHelpers.cs b/com.unity.netcode.gameobjects/Editor/CodeGen/CodeGenHelpers.cs index 473e84f219..1bb3ab1b16 100644 --- a/com.unity.netcode.gameobjects/Editor/CodeGen/CodeGenHelpers.cs +++ b/com.unity.netcode.gameobjects/Editor/CodeGen/CodeGenHelpers.cs @@ -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; } @@ -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)) { From ac2275f591991ced28d2b7dc607ca6173013f7aa Mon Sep 17 00:00:00 2001 From: Kitty Draper Date: Thu, 29 Jun 2023 14:41:27 -0500 Subject: [PATCH 2/3] changelog --- com.unity.netcode.gameobjects/CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/com.unity.netcode.gameobjects/CHANGELOG.md b/com.unity.netcode.gameobjects/CHANGELOG.md index 46cc459577..ee16567e6f 100644 --- a/com.unity.netcode.gameobjects/CHANGELOG.md +++ b/com.unity.netcode.gameobjects/CHANGELOG.md @@ -6,6 +6,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) Additional documentation and release notes are available at [Multiplayer Documentation](https://docs-multiplayer.unity3d.com). +## [Unreleased] + +### Fixed + +- Fixed an ILPP compile error when creating a generic NetworkBehaviour singleton with a static T instance. (#2603) + ## [1.5.1] - 2023-06-07 ### Added From 75aeaa37f5cd1d1e9300eeb0311ca3e13a230959 Mon Sep 17 00:00:00 2001 From: Kitty Draper Date: Fri, 30 Jun 2023 16:41:00 -0500 Subject: [PATCH 3/3] Added another fix for a similar issue. --- .../Editor/CodeGen/NetworkBehaviourILPP.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/com.unity.netcode.gameobjects/Editor/CodeGen/NetworkBehaviourILPP.cs b/com.unity.netcode.gameobjects/Editor/CodeGen/NetworkBehaviourILPP.cs index b7ad88ca88..84133fff0d 100644 --- a/com.unity.netcode.gameobjects/Editor/CodeGen/NetworkBehaviourILPP.cs +++ b/com.unity.netcode.gameobjects/Editor/CodeGen/NetworkBehaviourILPP.cs @@ -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) {