Invalid code generation with more than one Entity GhostField in 1.9.1

I have an component with 2 ghost entities, taken directly out of the character controller example. The class looks like this:

[GhostComponent]
public struct ThirdPersonPlayer : IComponentData
{
    [GhostField]
    public Entity ControlledCharacter;
    [GhostField]
    public Entity ControlledCamera;
}

Netcode for entities generates the following code:

static void CopyToSnapshotGenerated(in GhostSerializerState serializerState, ref Snapshot snapshot, ref ThirdPersonPlayer component)
        {
                snapshot.ControlledCharacter = 0;
                snapshot.ControlledCharacterSpawnTick = Unity.NetCode.NetworkTick.Invalid.SerializedData;
                if (serializerState.GhostFromEntity.TryGetComponent(component.ControlledCharacter, out var ghostComponent))
                {
                    snapshot.ControlledCharacter = ghostComponent.ghostId;
                    snapshot.ControlledCharacterSpawnTick = ghostComponent.spawnTick.SerializedData;
                }
                snapshot.ControlledCamera = 0;
                snapshot.ControlledCameraSpawnTick = Unity.NetCode.NetworkTick.Invalid.SerializedData;
                if (serializerState.GhostFromEntity.TryGetComponent(component.ControlledCamera, out var ghostComponent))
                {
                    snapshot.ControlledCamera = ghostComponent.ghostId;
                    snapshot.ControlledCameraSpawnTick = ghostComponent.spawnTick.SerializedData;
                }
        }

Note the 2 out var ghostComponent at the same scope. They produce the following error in the console:

Temp/NetCodeGenerated/Assembly-CSharp/2062241058503599662_ThirdPersonPlayerSerializer.cs(65,105): error CS0128: A local variable or function named 'ghostComponent' is already defined in this scope

This seems similar to an old bug:

I opened bug report case 123079 for this.

Similar to mine as well.

My reported case has just been put under review :grin:. I’ve added your GhostComponent code snippet and case number to my report, as it appears to be the same bug manifesting in different locations causing the same issue.

ty @CyborgRaven
My bug report also moved to in review. It definitely looks like a duplicate.

As a workaround I downgraded to 1.9.0, just update the manifest.json

Yeah, that can temporarily work around the issue, but upgrading the project to a higher Unity version will still fail due to the compile error.

Also, it seems the issue was already created (MTTB-1720) before I added your code snippet to my report (even before my report was put under review), so your code isn’t mentioned in the issue.

Just to clarify, the original ticket got stucked in the pipeline so the team didn’t get it before, after your thread @CyborgRaven I created ticket for us (as a measure before we will get the original ticket) + pinged around

I updated the description to include also your case @goldbug and we will prioritize fixing this this week

This has been fixed in the recently released 1.9.3 patch.