diff --git a/com.unity.netcode.gameobjects/Editor/CodeGen/NetworkBehaviourILPP.cs b/com.unity.netcode.gameobjects/Editor/CodeGen/NetworkBehaviourILPP.cs index 9c9c45f586..85943138be 100644 --- a/com.unity.netcode.gameobjects/Editor/CodeGen/NetworkBehaviourILPP.cs +++ b/com.unity.netcode.gameobjects/Editor/CodeGen/NetworkBehaviourILPP.cs @@ -595,8 +595,8 @@ private void ProcessNetworkBehaviour(TypeDefinition typeDefinition, string[] ass // override NetworkBehaviour.__getTypeName() method to return concrete type { - var baseType = typeDefinition.BaseType.Resolve(); - var baseGetTypeNameMethod = baseType.Methods.First(p => p.Name.Equals(nameof(NetworkBehaviour.__getTypeName))); + var networkBehaviour_TypeDef = m_NetworkBehaviour_TypeRef.Resolve(); + var baseGetTypeNameMethod = networkBehaviour_TypeDef.Methods.First(p => p.Name.Equals(nameof(NetworkBehaviour.__getTypeName))); var newGetTypeNameMethod = new MethodDefinition( nameof(NetworkBehaviour.__getTypeName), diff --git a/com.unity.netcode.gameobjects/Tests/Editor/NetworkBehaviourTests.cs b/com.unity.netcode.gameobjects/Tests/Editor/NetworkBehaviourTests.cs index e6d9607702..395aa79d95 100644 --- a/com.unity.netcode.gameobjects/Tests/Editor/NetworkBehaviourTests.cs +++ b/com.unity.netcode.gameobjects/Tests/Editor/NetworkBehaviourTests.cs @@ -47,14 +47,30 @@ public void AccessNetworkObjectTest() } [Test] - public void GetNetworkBehaviourNameTest() + public void GivenClassDerivesFromNetworkBehaviour_GetTypeNameReturnsCorrectValue() { - var gameObject = new GameObject(nameof(GetNetworkBehaviourNameTest)); + var gameObject = new GameObject(nameof(GivenClassDerivesFromNetworkBehaviour_GetTypeNameReturnsCorrectValue)); var networkBehaviour = gameObject.AddComponent(); Assert.AreEqual(nameof(EmptyNetworkBehaviour), networkBehaviour.__getTypeName()); } + [Test] + public void GivenClassDerivesFromNetworkBehaviourDerivedClass_GetTypeNameReturnsCorrectValue() + { + var gameObject = new GameObject(nameof(GivenClassDerivesFromNetworkBehaviourDerivedClass_GetTypeNameReturnsCorrectValue)); + var networkBehaviour = gameObject.AddComponent(); + + Assert.AreEqual(nameof(DerivedNetworkBehaviour), networkBehaviour.__getTypeName()); + } + + // Note: in order to repro https://github.com/Unity-Technologies/com.unity.netcode.gameobjects/issues/1078 + // this child class must be defined before its parent to assure it is processed first by ILPP + public class DerivedNetworkBehaviour : EmptyNetworkBehaviour + { + + } + public class EmptyNetworkBehaviour : NetworkBehaviour {