Search Issue Tracker
Fixed
Fixed in netcode-1.9.3, 1.10.X
Votes
3
Found in [Package]
netcode-1.9.1
netcode-1.10.0
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
Add comment
All about bugs
View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.
Latest issues
- Mono Windows Builds don't produce full log callstacks when generating logs
- AssetBundles fail to load when running in Built Players for Mobile Devices
- UI elements with text gets bigger and grey when Player window is moved to another screen with different resolution
- System name accepts multiline text but crops it on confirmation, duplicates input, and shrinks the field when empty
- UI element scale and position are wrong in project build when DRS is changed with HDR and Software Dynamic Resolution enabled
Resolution Note (fix version 1.10):
Thanks for the bug report. This came due to an issue with our templates. We have increased our coverage to prevent this regression again. We will release this with the 1.10.0 release and we will also create a patch for the 1.9 with this fix.