I’m stuck figuring out why my game works in the editor, but not in builds.
NetCode for Entities 1.2.3, Unity 2022.3.32f1, Mac.
When running the game in Editor either as one Client & Server or copying the game to a new location and opening it in two editors, the game connects and the GoInGameClientSystem and GoInGameServerSystem run. The game works fine.
But when I either build a dedicated server or build a client and try to connect it to the editor (serving as the other part),
- the connection happens
- the GoInGameClientSystem or GoInGameServerSystem in the editor run (do their OnUpdate)
- the GoInGameClientSystem or GoInGameServerSystem in the build do their OnCreate, but their OnUpdate does NOT run
When the server is run from a build, there’s an error message The referenced script on this Behaviour (Game Object '<null>') is missing!
that I can’t figure out. It doesn’t happen when run in the editor, so it could be related.
What am I doing wrong?
AutoConnectBootstrap.cs
using Unity.NetCode;
[UnityEngine.Scripting.Preserve]
public class AutoConnectBootstrap : ClientServerBootstrap
{
public override bool Initialize(string defaultWorldName)
{
AutoConnectPort = 0;
return base.Initialize(defaultWorldName);
}
}
ConnectionManager.cs
using System.Collections;
using Unity.Entities;
using Unity.NetCode;
using Unity.Networking.Transport;
using UnityEngine;
public class ConnectionManager : MonoBehaviour
{
[SerializeField] private string connectIp = "127.0.0.1";
[SerializeField] private ushort port = 7979;
private bool connecting;
private void Awake()
{
Application.runInBackground = true;
}
private void Start()
{
Connect();
}
public void Connect()
{
if (connecting) return;
connecting = true;
StartCoroutine(InitializeConnection());
}
private IEnumerator InitializeConnection()
{
var isServer = ClientServerBootstrap.RequestedPlayType == ClientServerBootstrap.PlayType.Server || ClientServerBootstrap.RequestedPlayType == ClientServerBootstrap.PlayType.ClientAndServer;
var isClient = ClientServerBootstrap.RequestedPlayType == ClientServerBootstrap.PlayType.Client || ClientServerBootstrap.RequestedPlayType == ClientServerBootstrap.PlayType.ClientAndServer;
Debug.Log($"ConnectionManager: Initializing connection {isServer}/{isClient} ...");
while ((isServer && !ClientServerBootstrap.HasServerWorld) || (isClient && !ClientServerBootstrap.HasClientWorlds))
{
yield return null;
}
Debug.Log($"ConnectionManager: World(s) created.");
try
{
if (isServer)
{
using var query = ServerWorld.EntityManager.CreateEntityQuery(ComponentType.ReadWrite<NetworkStreamDriver>());
query.GetSingletonRW<NetworkStreamDriver>().ValueRW.Listen(ClientServerBootstrap.DefaultListenAddress.WithPort(port));
Debug.Log($"ConnectionManager: Server listening on port {port} ...");
}
if (isClient)
{
var world = ClientWorld;
using var query = world.EntityManager.CreateEntityQuery(ComponentType.ReadWrite<NetworkStreamDriver>());
query.GetSingletonRW<NetworkStreamDriver>().ValueRW.Connect(world.EntityManager, NetworkEndpoint.Parse(connectIp, port));
Debug.Log($"ConnectionManager: Client connected to {connectIp}:{port}.");
}
}
catch (System.Exception ex)
{
Debug.LogError(ex);
}
finally
{
connecting = false;
}
Debug.Log($"ConnectionManager: Setup complete.");
}
public static World ServerWorld
{
get
{
foreach (var world in World.All)
{
if (world.Flags != WorldFlags.GameServer) continue;
return world;
}
return null;
}
}
public static World ClientWorld
{
get
{
foreach (var world in World.All)
{
if (world.Flags != WorldFlags.GameClient) continue;
return world;
}
return null;
}
}
}
GoInGameSystem.cs
using UnityEngine;
using Unity.Burst;
using Unity.Collections;
using Unity.Entities;
using Unity.NetCode;
using Unity.Transforms;
[BurstCompile]
[WorldSystemFilter(WorldSystemFilterFlags.ClientSimulation | WorldSystemFilterFlags.ServerSimulation | WorldSystemFilterFlags.ThinClientSimulation)]
[UpdateInGroup(typeof(InitializationSystemGroup))]
[CreateAfter(typeof(RpcSystem))]
public partial struct SetRpcSystemDynamicAssemblyListSystem : ISystem
{
public void OnCreate(ref SystemState state)
{
Debug.Log($"{nameof(SetRpcSystemDynamicAssemblyListSystem)}.{nameof(OnCreate)}");
SystemAPI.GetSingletonRW<RpcCollection>().ValueRW.DynamicAssemblyList = true;
state.Enabled = false;
}
}
public struct GoInGameRequest : IRpcCommand
{
}
[BurstCompile]
[WorldSystemFilter(WorldSystemFilterFlags.ClientSimulation | WorldSystemFilterFlags.ThinClientSimulation)]
public partial struct GoInGameClientSystem : ISystem
{
[BurstCompile]
public void OnCreate(ref SystemState state)
{
Debug.Log($"{nameof(GoInGameClientSystem)}.{nameof(OnCreate)}");
var builder = new EntityQueryBuilder(Allocator.Temp)
.WithAll<NetworkId>()
.WithNone<NetworkStreamInGame>();
state.RequireForUpdate(state.GetEntityQuery(builder));
}
[BurstCompile]
public void OnUpdate(ref SystemState state)
{
Debug.Log($"GoInGameClientSystem.OnUpdate ...");
using var commandBuffer = new EntityCommandBuffer(Allocator.Temp);
foreach (var (id, entity) in SystemAPI.Query<RefRO<NetworkId>>().WithEntityAccess().WithNone<NetworkStreamInGame>())
{
Debug.Log($"GoInGameClientSystem.OnUpdate NetworkId {id.ValueRO.Value}");
commandBuffer.AddComponent<NetworkStreamInGame>(entity);
var req = commandBuffer.CreateEntity();
commandBuffer.AddComponent<GoInGameRequest>(req);
commandBuffer.AddComponent(req, new SendRpcCommandRequest { TargetConnection = entity });
}
commandBuffer.Playback(state.EntityManager);
}
}
[BurstCompile]
[WorldSystemFilter(WorldSystemFilterFlags.ServerSimulation)]
public partial struct GoInGameServerSystem : ISystem
{
private ComponentLookup<NetworkId> networkIdFromEntity;
[BurstCompile]
public void OnCreate(ref SystemState state)
{
Debug.Log($"{nameof(GoInGameServerSystem)}.{nameof(OnCreate)}");
state.RequireForUpdate<PlayerSpawner>();
var builder = new EntityQueryBuilder(Allocator.Temp)
.WithAll<GoInGameRequest>()
.WithAll<ReceiveRpcCommandRequest>();
state.RequireForUpdate(state.GetEntityQuery(builder));
networkIdFromEntity = state.GetComponentLookup<NetworkId>(true);
}
[BurstCompile]
public void OnUpdate(ref SystemState state)
{
Debug.Log($"GoInGameServerSystem.OnUpdate ...");
PlayerSpawner playerSpawner = SystemAPI.GetSingleton<PlayerSpawner>();
state.EntityManager.GetName(playerSpawner.PlayerPrefab, out var prefabName);
var worldName = state.WorldUnmanaged.Name;
using var commandBuffer = new EntityCommandBuffer(Allocator.Temp);
networkIdFromEntity.Update(ref state);
foreach (var (reqSrc, reqEntity) in SystemAPI.Query<RefRO<ReceiveRpcCommandRequest>>().WithAll<GoInGameRequest>().WithEntityAccess())
{
commandBuffer.AddComponent<NetworkStreamInGame>(reqSrc.ValueRO.SourceConnection);
var networkId = networkIdFromEntity[reqSrc.ValueRO.SourceConnection];
Debug.Log($"GoInGameServerSystem.OnUpdate '{worldName}' setting connection '{networkId.Value}'");
var player = commandBuffer.Instantiate(playerSpawner.PlayerPrefab);
// Associate the instantiated prefab with the connected client's assigned NetworkId
commandBuffer.SetComponent(player, new GhostOwner { NetworkId = networkId.Value });
commandBuffer.SetComponent(player, LocalTransform.FromPosition(playerSpawner.SpawnPosition));
Debug.Log($"GoInGameServerSystem.OnUpdate instantiating {prefabName} for connection '{networkId.Value}'");
// Add the player to the linked entity group so it is destroyed automatically on disconnect
commandBuffer.AppendToBuffer(reqSrc.ValueRO.SourceConnection, new LinkedEntityGroup { Value = player });
commandBuffer.DestroyEntity(reqEntity);
}
commandBuffer.Playback(state.EntityManager);
}
}
For example, when running a dedicated server build and the Editor in client mode:
Client Logs (Editor)
GoInGameClientSystem.OnCreate
SetRpcSystemDynamicAssemblyListSystem.OnCreate
FollowPlayerSystem.OnCreate
ConnectionManager: Initializing connection False/True ...
ConnectionManager: World(s) created.
ConnectionManager: Client connected to 127.0.0.1:7979.
ConnectionManager: Setup complete.
GoInGameClientSystem.OnUpdate ...
GoInGameClientSystem.OnUpdate NetworkId 1
Server Logs (Build): GoInGameServerSystem.OnUpdate does NOT run
The The referenced script on this Behaviour (Game Object '<null>') is missing!
could be relevant, I guess. I can’t figure out what it is though.
[UnityMemory] Configuration Parameters - Can be set up in boot.config
"memorysetup-bucket-allocator-granularity=16"
"memorysetup-bucket-allocator-bucket-count=8"
"memorysetup-bucket-allocator-block-size=4194304"
"memorysetup-bucket-allocator-block-count=1"
"memorysetup-main-allocator-block-size=16777216"
"memorysetup-thread-allocator-block-size=16777216"
"memorysetup-gfx-main-allocator-block-size=16777216"
"memorysetup-gfx-thread-allocator-block-size=16777216"
"memorysetup-cache-allocator-block-size=4194304"
"memorysetup-typetree-allocator-block-size=2097152"
"memorysetup-profiler-bucket-allocator-granularity=16"
"memorysetup-profiler-bucket-allocator-bucket-count=8"
"memorysetup-profiler-bucket-allocator-block-size=4194304"
"memorysetup-profiler-bucket-allocator-block-count=1"
"memorysetup-profiler-allocator-block-size=16777216"
"memorysetup-profiler-editor-allocator-block-size=1048576"
"memorysetup-temp-allocator-size-main=4194304"
"memorysetup-job-temp-allocator-block-size=2097152"
"memorysetup-job-temp-allocator-block-size-background=1048576"
"memorysetup-job-temp-allocator-reduction-small-platforms=262144"
"memorysetup-allocator-temp-initial-block-size-main=262144"
"memorysetup-allocator-temp-initial-block-size-worker=262144"
"memorysetup-temp-allocator-size-background-worker=32768"
"memorysetup-temp-allocator-size-job-worker=262144"
"memorysetup-temp-allocator-size-preload-manager=262144"
"memorysetup-temp-allocator-size-nav-mesh-worker=65536"
"memorysetup-temp-allocator-size-audio-worker=65536"
"memorysetup-temp-allocator-size-cloud-worker=32768"
"memorysetup-temp-allocator-size-gfx=262144"
Mono path[0] = '/Users/me/Dropbox/Projects/WOP/Builds/Mac Server/Data/Managed'
Mono config path = '/Users/me/Dropbox/Projects/WOP/Builds/Mac Server/MonoBleedingEdge/etc'
[PhysX] Initialized MultithreadedTaskDispatcher with 8 workers.
Initialize engine version: 2022.3.32f1 (c8300dc0a3fa)
[Subsystems] Discovering subsystems at path /Users/me/Dropbox/Projects/WOP/Builds/Mac Server/Data/UnitySubsystems
Forcing GfxDevice: Null
GfxDevice: creating device client; threaded=0; jobified=0
NullGfxDevice:
Version: NULL 1.0 [1.0]
Renderer: Null Device
Vendor: Unity Technologies
Begin MonoManager ReloadAssembly
- Loaded All Assemblies, in 0.103 seconds
- Finished resetting the current domain, in 0.001 seconds
There is no texture data available to upload.
There is no texture data available to upload.
[PhysX] Initialized MultithreadedTaskDispatcher with 8 workers.
UnloadTime: 2.218292 ms
SetRpcSystemDynamicAssemblyListSystem.OnCreate
GoInGameServerSystem.OnCreate
Invalid VFX Particle System. It is skipped.
Unable to use Blit. Shader is not yet initialized!
Cannot create required material because shader is null
Cannot create required material because shader is null
Cannot create required material because shader is null
Cannot create required material because shader is null
Cannot create required material because shader is null
Cannot create required material because shader is null
Cannot create required material because shader is null
Missing shader. ColorGradingLutPass render pass will not execute. Check for missing reference in the renderer resources.
Missing shader. ColorGradingLutPass render pass will not execute. Check for missing reference in the renderer resources.
Missing shader. PostProcessing render passes will not execute. Check for missing reference in the renderer resources.
Missing shader. PostProcessing render passes will not execute. Check for missing reference in the renderer resources.
Missing shader. PostProcessing render passes will not execute. Check for missing reference in the renderer resources.
Missing shader. PostProcessing render passes will not execute. Check for missing reference in the renderer resources.
Missing shader. PostProcessing render passes will not execute. Check for missing reference in the renderer resources.
Missing shader. PostProcessing render passes will not execute. Check for missing reference in the renderer resources.
Missing shader. PostProcessing render passes will not execute. Check for missing reference in the renderer resources.
Missing shader. PostProcessing render passes will not execute. Check for missing reference in the renderer resources.
Missing shader. PostProcessing render passes will not execute. Check for missing reference in the renderer resources.
Missing shader. PostProcessing render passes will not execute. Check for missing reference in the renderer resources.
Missing shader. PostProcessing render passes will not execute. Check for missing reference in the renderer resources.
Missing shader. PostProcessing render passes will not execute. Check for missing reference in the renderer resources.
Missing shader. PostProcessing render passes will not execute. Check for missing reference in the renderer resources.
Missing shader. PostProcessing render passes will not execute. Check for missing reference in the renderer resources.
Missing shader. PostProcessing render passes will not execute. Check for missing reference in the renderer resources.
Missing shader. PostProcessing render passes will not execute. Check for missing reference in the renderer resources.
Missing shader. PostProcessing render passes will not execute. Check for missing reference in the renderer resources.
Missing shader. PostProcessing render passes will not execute. Check for missing reference in the renderer resources.
Missing shader. PostProcessing render passes will not execute. Check for missing reference in the renderer resources.
Missing shader. PostProcessing render passes will not execute. Check for missing reference in the renderer resources.
Missing shader. PostProcessing render passes will not execute. Check for missing reference in the renderer resources.
Missing shader. PostProcessing render passes will not execute. Check for missing reference in the renderer resources.
Missing shader. PostProcessing render passes will not execute. Check for missing reference in the renderer resources.
Missing shader. PostProcessing render passes will not execute. Check for missing reference in the renderer resources.
Missing shader. PostProcessing render passes will not execute. Check for missing reference in the renderer resources.
Missing shader. PostProcessing render passes will not execute. Check for missing reference in the renderer resources.
Cannot create required material because shader is null
Cannot create required material because shader is null
Cannot initialize a LocalKeyword with a null Shader.
NullReferenceException: Object reference not set to an instance of an object
at UnityEngine.Rendering.LocalKeyword..ctor (UnityEngine.Shader shader, System.String name) [0x00017] in <185c0568965e4d679fb36d383d78df6d>:0
at UnityEngine.Rendering.Blitter.Initialize (UnityEngine.Shader blitPS, UnityEngine.Shader blitColorAndDepthPS) [0x0002e] in <3c4028dceecf4b458de9eadac206172a>:0
at UnityEngine.Rendering.Universal.UniversalRenderPipelineAsset.CreatePipeline () [0x000a4] in <42326b7effc14e17a681c27c50fe04b3>:0
at UnityEngine.Rendering.RenderPipelineAsset.InternalCreatePipeline () [0x00004] in <185c0568965e4d679fb36d383d78df6d>:0
UnityEngine.DebugLogHandler:Internal_LogException(Exception, Object)
UnityEngine.DebugLogHandler:LogException(Exception, Object)
UnityEngine.Logger:LogException(Exception, Object)
UnityEngine.Debug:LogException(Exception)
UnityEngine.Rendering.RenderPipelineAsset:InternalCreatePipeline()
UnityEngine.Rendering.RenderPipelineManager:PrepareRenderPipeline(RenderPipelineAsset)
UnityEngine.Rendering.RenderPipelineManager:smile:oRenderLoop_Internal(RenderPipelineAsset, IntPtr, Object)
UnityEngine.Camera:Render(Camera)
<RenderCamera>d__6:MoveNext()
UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)
UnityEngine.MonoBehaviour:StartCoroutineManaged2(MonoBehaviour, IEnumerator)
UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator)
MinimapCamera:OnEnable()
ConnectionManager: Initializing connection True/False ...
ConnectionManager: World(s) created.
ConnectionManager: Server listening on port 7979 ...
ConnectionManager: Setup complete.
The referenced script on this Behaviour (Game Object '<null>') is missing!
WARNING: Shader Unsupported: 'Hidden/Universal Render Pipeline/FallbackError' - All subshaders removed
WARNING: Shader Did you use #pragma only_renderers and omit this platform?
WARNING: Shader If subshaders removal was intentional, you may have forgotten turning Fallback off?
ERROR: Shader Hidden/Universal Render Pipeline/FallbackError shader is not supported on this GPU (none of subshaders/fallbacks are suitable)
WARNING: Shader Unsupported: 'Hidden/Universal Render Pipeline/FallbackError' - All subshaders removed
WARNING: Shader Did you use #pragma only_renderers and omit this platform?
WARNING: Shader If subshaders removal was intentional, you may have forgotten turning Fallback off?
ERROR: Shader Sprites/Default shader is not supported on this GPU (none of subshaders/fallbacks are suitable)
WARNING: Shader Unsupported: 'Universal Render Pipeline/2D/Sprite-Lit-Default' - All subshaders removed
WARNING: Shader Did you use #pragma only_renderers and omit this platform?
WARNING: Shader If subshaders removal was intentional, you may have forgotten turning Fallback off?
ERROR: Shader Universal Render Pipeline/2D/Sprite-Lit-Default shader is not supported on this GPU (none of subshaders/fallbacks are suitable)
WARNING: Shader Unsupported: 'Universal Render Pipeline/2D/Sprite-Lit-Default' - All subshaders removed
WARNING: Shader Did you use #pragma only_renderers and omit this platform?
WARNING: Shader If subshaders removal was intentional, you may have forgotten turning Fallback off?
WARNING: Shader Unsupported: 'Universal Render Pipeline/Lit' - All subshaders removed
WARNING: Shader Did you use #pragma only_renderers and omit this platform?
WARNING: Shader If subshaders removal was intentional, you may have forgotten turning Fallback off?
ERROR: Shader Universal Render Pipeline/Lit shader is not supported on this GPU (none of subshaders/fallbacks are suitable)
WARNING: Shader Unsupported: 'Universal Render Pipeline/Lit' - All subshaders removed
WARNING: Shader Did you use #pragma only_renderers and omit this platform?
WARNING: Shader If subshaders removal was intentional, you may have forgotten turning Fallback off?
ERROR: Shader Hidden/VFX/Clouds/System (1)/Output Particle URP Lit Mesh shader is not supported on this GPU (none of subshaders/fallbacks are suitable)
When I run the server in the Editor and a built client:
Server Logs (Editor): GoInGameServerSystem.OnUpdate runs
SetRpcSystemDynamicAssemblyListSystem.OnCreate
GoInGameServerSystem.OnCreate
ConnectionManager: Initializing connection True/False ...
ConnectionManager: World(s) created.
ConnectionManager: Server listening on port 7979 ...
ConnectionManager: Setup complete.
GoInGameServerSystem.OnUpdate ...
GoInGameServerSystem.OnUpdate 'ServerWorld' setting connection '1'
GoInGameServerSystem.OnUpdate instantiating for connection '1'