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
- Assets are created in the Package folders when creating assets via custom buttons in the Inspector window or other windows
- “Select” windows are named differently on Windows and macOS
- [Windows] No minimum “Select” window size
- Enabling “Editor Extension Authoring” in UI Builder doesn’t dirty the document and saving with shortcut doesn’t persist the state
- WebRequest.Create() function fails with "URI prefix is not recognized" errors when the project is built for Linux Standalone or Windows Dedicated Server
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.