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.