[1.2.0-exp.3] Changing Value On Replicated Child Entity Component On Prespawned Results In Mismatch

Add the following code to a prespawned entity.

The following error will occur:
Subscene 4798306647990229215 baseline mismatch. Server:14097450156539151812 Client:1450044529518037442

This is due to TestSys changing the value of TestComp on the first frame when subscene is loaded.

By delaying the start of changing the value in TestSys, everything works fine.

Basically, children of prespawned ghosts need the disabled tag that their parents also have. Or recommend that children of prespawned need to check their parents for disabled tag before changing any values.

using Unity.Burst;
using Unity.Collections;
using Unity.Entities;
using Unity.NetCode;
using UnityEngine;

public class TestAuthoring : MonoBehaviour
{
    private class Oven : Baker<MapAuthoring>
    {
        public override void Bake(TestAuthoring authoring)
        {
            var t1 = new NativeArray<Entity>(1, Allocator.Temp);
            CreateAdditionalEntities(t1, TransformUsageFlags.Dynamic);
            foreach (Entity ent in t1)
                AddComponent<TestComp>(ent);
        }
    }
}

[GhostComponent(SendDataForChildEntity = true)]
public struct TestComp : IComponentData
{
    [GhostField] public int Value;
}

[WorldSystemFilter(WorldSystemFilterFlags.ServerSimulation)]
public partial struct TestSys : ISystem
{
    [BurstCompile]
    public void OnUpdate(ref SystemState state)
    {
        foreach (var comp in SystemAPI.Query<RefRW<TestComp>>())
        {
            comp.ValueRW.Value++;
        }
    }
}

Yeah, right on mark! That should have been already the case. Thanks for reporting!

1 Like