Not signed in
Copyright © 2026 Unity Technologies
As reported in https://discussions.unity.com/t/netcode-for-entities-1-9-1-released/1690861. A similar issue was pointed out in https://discussions.unity.com/t/invalid-code-generation-with-more-than-one-entity-ghostfield-in-1-9-1/1693262 so this should be double checked if the fix will apply to both cases
* GhostSnapshotValueEntity now uses TryGetValue rather than a HasComponent call followed by a lookup, reducing lookup costs.
This is causing a problem.
A simple RPC command like this results in a compile error.
public struct BugComponent : IRpcCommand { public Entity E1; public Entity E2; }
The generated code under “Temp\NetCodeGenerated\Unity.NetCode” has a snippet like this:
public void Serialize(ref DataStreamWriter writer, in RpcSerializerState state, in BugComponent data) { if (state.GhostFromEntity.TryGetComponent(data.E1, out var ghostComponent)) { writer.WriteInt(ghostComponent.ghostId); writer.WriteUInt(ghostComponent.spawnTick.SerializedData); } else { writer.WriteInt(0); writer.WriteUInt(Unity.NetCode.NetworkTick.Invalid.SerializedData); } if (state.GhostFromEntity.TryGetComponent(data.E2, out var ghostComponent)) { writer.WriteInt(ghostComponent.ghostId); writer.WriteUInt(ghostComponent.spawnTick.SerializedData); } else { writer.WriteInt(0); writer.WriteUInt(Unity.NetCode.NetworkTick.Invalid.SerializedData); } }
The out var ghostComponent in line 3 and line 13 are in the same scope - outside of the if block. Thus, error CS0128: A local variable or function named 'ghostComponent' is already defined in this scope.
This did not happen in 1.9.0 since when using HasComponent, the ghostComponent was defined inside the if blocks, which have separated scopes.
NOTE that this seems like perfect case that should be reproducible by RPC sample in NetcodeSamples which is not true since RPC sample works perfectly fine. I would argue that as part of this fix we should also modify RPC sample to be able to catch such issues
Sign in to see your voted issues