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

Question Troubles with raycasting, netcode and client-only worlds

Discussion in 'NetCode for ECS' started by Noek1993, Aug 24, 2023.

  1. Noek1993

    Noek1993

    Joined:
    Jan 22, 2015
    Posts:
    25
    Hello!

    For a game I have a world filled with generated static colliders. These colliders are used for raycasting (object under mouse) for the selection of objects. This works running the game in local mode without netcode, however when running the same systems in the client-world the raycast fail to detect anything. When using the debugger I noticed that the collision world in the PhysicsWorldSingleton seems to contain no bodies. I tried using moving the raycasting to a system running in the PhysicsSimulationGroup system group, however the system does not seem to ever run when running the game with netcode for entities.

    I create these colliders from code using the following method
    Code (CSharp):
    1.  
    2.         public static Entity CreateBody (EntityManager entityManager, float3 position, quaternion orientation, BlobAssetReference<Collider> collider, uint world = 0)
    3.         {
    4.             var entity = entityManager.CreateEntity(typeof(LocalTransform), typeof(PhysicsCollider), typeof(PhysicsWorldIndex));
    5.  
    6.             entityManager.SetComponentData(entity, new LocalTransform
    7.             {
    8.                 Position = position,
    9.                 Rotation = orientation,
    10.                 Scale = 1
    11.             });
    12.             entityManager.SetComponentData(entity, new PhysicsCollider { Value = collider });
    13.             entityManager.SetSharedComponentManaged(entity, new PhysicsWorldIndex { Value = world });
    14.             return entity;
    15.         }
    16.  
    Originally I got a message telling me I need to make a client-only physics world, I followed the step mentioned at: https://docs.unity3d.com/Packages/com.unity.netcode@1.0/manual/physics.html
    However this also does not seem produce a populated collision world and neither do the physics systems run.

    I did create a subscene with NetCodePhysicsConfig setting the client-only world to 1 and creating a custom group:
    Code (CSharp):
    1.  
    2.     [WorldSystemFilter(WorldSystemFilterFlags.ClientSimulation | WorldSystemFilterFlags.LocalSimulation)]
    3.     [UpdateInGroup(typeof(FixedStepSimulationSystemGroup))]
    4.     public partial class VisualizationPhysicsSystemGroup : CustomPhysicsSystemGroup
    5.     {
    6.         public VisualizationPhysicsSystemGroup () : base(1, false) { }
    7.     }
    8.  
    And update the CreateBody method to use world 1 as a default instead of 0.

    Why are the physics worlds not running or being generated or filled?
    And what is the best way for client-side raycasting against client created colliders using netcode?
     
  2. CMarastoni

    CMarastoni

    Unity Technologies

    Joined:
    Mar 18, 2020
    Posts:
    774
    This is a bug in current released Netcode that prevent the physics to run if there aren't predicted ghost with physics in the world.
    As a work around, please enable the Lag Componensation by using the PhysicsConfigAuthoring.
    There is no reason to add a client-only physics world for this.
     
  3. Noek1993

    Noek1993

    Joined:
    Jan 22, 2015
    Posts:
    25
    Thanks for your answer. This does make the physics system run in the server world.
    However in the client world the physics systems still do not run and the collision world does not get build.
    Both the server and client world contain the `LagCompensationConfig` singleton.

    When doing some debugging it seems like the `NetcodeClientPredictionRateManager` always returns false because the `appliedPredictedTicks` are empty.
     
    Last edited: Sep 5, 2023
  4. CMarastoni

    CMarastoni

    Unity Technologies

    Joined:
    Mar 18, 2020
    Posts:
    774
    You still need to have at least one predicted ghost in your game to make this system run.
     
  5. Szejp

    Szejp

    Joined:
    Apr 6, 2017
    Posts:
    5
    Hello, any more news on that? Adding ghost authoring component into one of the sub scenes does not seem to solve the issue.
     
  6. Asoprachev

    Asoprachev

    Joined:
    Aug 13, 2017
    Posts:
    9
    It's works for me, on ghost authoring component should be selected "predicted ghost mode". But I also wait when this be fixed.

    For disable rollback overhead for this predicted ghost, I remove PhysicsVelocity, Mass and Gravity components from it, as soon as non zero PhysicsWorldSingleton.PhysicsWorldIndex exists
     
  7. Szejp

    Szejp

    Joined:
    Apr 6, 2017
    Posts:
    5
    You do have num bodies more than 0? I keep having nulls everywhere. Raycasting things in just client mode seems to be impossible right now.