Search Issue Tracker
Active
Votes
2
Found in [Package]
netcode-1.9.1
Issue ID
MTTB-1720
Regression
Yes
N4E RPC results in compile error
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
{code:java}
- GhostSnapshotValueEntity now uses TryGetValue rather than a HasComponent call followed by a lookup, reducing lookup costs.
 
{code}
This is causing a problem.
A simple RPC command like this results in a compile error.
{code:java}
public struct BugComponent : IRpcCommand
{
public Entity E1;
public Entity E2;
}
{code}
The generated code under “Temp\NetCodeGenerated\Unity.NetCode” has a snippet like this:
{code:java}
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);
}
}
{code}
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
All about bugs
View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.
Latest issues
- Video does not play in macOS build when built app is placed in a path with a space in it on a specific project
 - Crash on AuxWindowManager::OnGotFocus when trying to maximize a tab while Visual Effect Graph window is open
 - “NullReferenceException: Object reference not set to an instance of an object” error is thrown when
 - [Metal] Game freezes after command buffer Timeout error
 - Addressables Report window UI is broken when opening via Build > New Build > Default Build Script
 
Add comment