Closed
Description
Need Netcode version 1.0.0-pre.8-9
Reproduce Steps
Create a templated class derived from NetworkBehaviour like
using UnityEngine;
using Unity.Netcode;
public class Singleton<T> : NetworkBehaviour
where T : Component
{
private static T _instance;
public static T Instance
{
get
{
if (_instance == null)
{
var objs = FindObjectsOfType(typeof(T)) as T[];
if (objs.Length > 0)
_instance = objs[0];
if (objs.Length > 1)
{
Debug.LogError("There is more than one " + typeof(T).Name + " in the scene.");
}
if (_instance == null)
{
GameObject obj = new GameObject();
obj.name = string.Format("_{0}", typeof(T).Name);
_instance = obj.AddComponent<T>();
}
}
return _instance;
}
}
}
Then go to unity
Actual Outcome
(0,0): error - System.NullReferenceException: Object reference not set to an instance of an object.|| at Unity.Netcode.Editor.CodeGen.INetworkSerializableILPP.Process(ICompiledAssembly compiledAssembly) in blah\Library\PackageCache\com.unity.netcode.gameobjects@1.0.0-pre.8-9\Editor\CodeGen\INetworkSerializableILPP.cs:line 116 at Unity.Netcode.Editor.CodeGen.INetworkSerializableILPP.Process(ICompiledAssembly compiledAssembly) in blah\Library\PackageCache\com.unity.netcode.gameobjects@1.0.0-pre.8-9\Editor\CodeGen\INetworkSerializableILPP.cs:line 116
Metadata
Metadata
Assignees
Labels
No labels