Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

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

Discussion in 'NetCode for ECS' started by Kmsxkuse, Nov 18, 2023.

  1. Kmsxkuse

    Kmsxkuse

    Joined:
    Feb 15, 2019
    Posts:
    304
    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.
    Code (CSharp):
    1. using Unity.Burst;
    2. using Unity.Collections;
    3. using Unity.Entities;
    4. using Unity.NetCode;
    5. using UnityEngine;
    6.  
    7. public class TestAuthoring : MonoBehaviour
    8. {
    9.     private class Oven : Baker<MapAuthoring>
    10.     {
    11.         public override void Bake(TestAuthoring authoring)
    12.         {
    13.             var t1 = new NativeArray<Entity>(1, Allocator.Temp);
    14.             CreateAdditionalEntities(t1, TransformUsageFlags.Dynamic);
    15.             foreach (Entity ent in t1)
    16.                 AddComponent<TestComp>(ent);
    17.         }
    18.     }
    19. }
    20.  
    21. [GhostComponent(SendDataForChildEntity = true)]
    22. public struct TestComp : IComponentData
    23. {
    24.     [GhostField] public int Value;
    25. }
    26.  
    27. [WorldSystemFilter(WorldSystemFilterFlags.ServerSimulation)]
    28. public partial struct TestSys : ISystem
    29. {
    30.     [BurstCompile]
    31.     public void OnUpdate(ref SystemState state)
    32.     {
    33.         foreach (var comp in SystemAPI.Query<RefRW<TestComp>>())
    34.         {
    35.             comp.ValueRW.Value++;
    36.         }
    37.     }
    38. }
     
  2. CMarastoni

    CMarastoni

    Unity Technologies

    Joined:
    Mar 18, 2020
    Posts:
    873
    Yeah, right on mark! That should have been already the case. Thanks for reporting!
     
    Kmsxkuse likes this.