Question by
yousefkmail · May 29 at 03:23 PM ·
networking
NetworkBehaviour problem
using Unity.Netcode;
using UnityEngine;
namespace DilmerGames.Core.Singletons
{
public class NetworkSingleton<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)
{
}
if (_instance == null)
{
GameObject obj = new GameObject();
obj.name = string.Format("_{0}", typeof(T).Name);
_instance = obj.AddComponent<T>();
}
}
return _instance;
}
}
}
}
Anyone knows what is wrong with this code even that i did it exactly as a code on the internet that is working ,I receive this message
(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 C:\Users\ykyou\My project\Library\PackageCache\com.unity.netcode.gameobjects@1.0.0-pre.9\Editor\CodeGen\INetworkSerializableILPP.cs:line 116 at Unity.Netcode.Editor.CodeGen.INetworkSerializableILPP.Process(ICompiledAssembly compiledAssembly) in C:\Users\ykyou\My project\Library\PackageCache\com.unity.netcode.gameobjects@1.0.0-pre.9\Editor\CodeGen\INetworkSerializableILPP.cs:line 116
Comment