Netcode for Entities 1.9.1 released

:package: Netcode for Entities 1.9.1 is now live! :package:

Key Updates in This Release

This patch improves the host migration system data gathering speed, it also brings some fixes to code generated fields and more.

Changed
  • Host migration system now caches the ghost component types it uses when collecting host migration ghost data, resulting in faster host migration data collections. It’s updated any time the ghost prefab count changes.
  • GhostField.Quantization template mismatch errors are now warnings, and will resolve to working code, rather than outputting errors. As a result, we will no longer assume primitive integer types want to disable quantization, as that logic did not cover all cases (e.g. like Entity structs etc).
  • Host migration internal ghost data gathering has improved and should be faster now but add a few bytes of extra data compared to before.
Fixed
  • Occasional MultiplayerPlayModeWindow.HandleHyperLinkArgs truncation error spam.
  • Unsafe compiler error when using a fixed array as a GhostField. Note: You must implement a corresponding safe accessor method implementing ref returns.
  • GhostField compiler error when using FixedList with nested struct types, as well as related InvalidOperationException in a SubString call when using a FixedList with a primitive type.
  • Code generator incorrectness when generating struct fields for GhostField FixedList and fixed array serializers (Entity fields in particular).
  • Incorrect curChangeMaskBits offset after a FixedList field is generated, due to incorrect aggregateChangeMask flag. It’s now forced correct via forceComposite.
  • FixedList’s and unsafe fixed array) now correctly support non-public structs for the element type (in cases where we know the code-gen will resolve without compiler errors).
  • GhostSnapshotValueEntity now uses TryGetValue rather than a HasComponent call followed by a lookup, reducing lookup costs.
  • Issue where specifying a LogLevel (via the Default.globalconfig’s unity.netcode.sourcegenerator.logging_level property) did nothing.
2 Likes

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.

That’s a bug on our end, do you mind bugging this using the Help/Report a Bug menu in Unity please? That’ll help us better track it. Thanks a bunch and sorry about this!

This was reported two weeks ago (IN-121079), but there has been no response. The bug itself is quite straightforward and shouldn’t be difficult to fix, but its impact is severe (Compile Error). That’s why I’m bringing it up again here, hoping to draw attention to it. Please prioritize getting this bug into the evaluation and fix process. Thank you!

1 Like