Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Resolved Unity Netcode - 3 entities of same ghost in client world?

Discussion in 'NetCode for ECS' started by Samsle, Aug 21, 2020.

  1. Samsle

    Samsle

    Joined:
    Mar 31, 2020
    Posts:
    103
    Hey, I have some misunderstanding problems with Unity Netcode, especially the ghosts.
    1. In the NetCube example, if I check in RunTime the "Entity Debugger" in the clientworld, I see there 3 cube entities (all with component "MovableCubeComponent"). One of it gets its Position changed if I move it, but the other both not.
      So what are the 2 other entities for?
    2. If a attach a IConvertGameObjectToEntity script to the cube prefab, I have there a Convert() method.
      What I don't get is, I create there a new entity, which should hold a component with a reference to the ghost. It creates exactly 2 new entities for both cube entities which Position got not changed.
      Code (CSharp):
      1. public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
      2. {
      3.      Entity newEntity = dstManager.CreateEntity();
      4.      dstManager.AddComponentData(newEntity, new ComponentX { ghostEntity = entity });
      5. }
      But if I add here a component to the cube entitiy, then the component will be on all 3 cube entities.
      Why is no entity created for the 3. cube entity?

    3. Also, how can I figure out in Convert() which entity is now the real "client" entity (on which the Position gets changed correctly)?
     
  2. timjohansson

    timjohansson

    Unity Technologies

    Joined:
    Jul 13, 2016
    Posts:
    473
    Two of them are prefabs, there is a prefab for the interpolated version of the ghost and a prefab for the predicted version of the ghost. Both of those have a prefab component on them.
    The third one is your instance of the ghost and it instantiated from one of your two prefabs depending on if it is predicted or not.
     
    bb8_1 and Samsle like this.
  3. Samsle

    Samsle

    Joined:
    Mar 31, 2020
    Posts:
    103
    ah got it, thank you Tim! :)