Search Issue Tracker
Fixed
Fixed in 1.10.0
Votes
3
Found in [Package]
1.9.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
- “FMOD failed to set the software format to the custom sample rate…” warnings are thrown as System Sample Rate value is being changed in Audio section of Project Settings window
- VFX Marquee selection does match the visual indicator
- “Invalid AABB aabb” errors are spammed when “Infinity” value is entered in Collider Component fields
- Editor Role does not sync with the MPPM Play Mode Scenario Role when entering Play mode
- Long asset names cause overlap with the “Find” function in search result tabs
Resolution Note:
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.