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 1.0.0-exp.8: how do I enable predicted physics?

Discussion in 'NetCode for ECS' started by sirwhatevers, Oct 12, 2022.

  1. sirwhatevers

    sirwhatevers

    Joined:
    Aug 25, 2017
    Posts:
    33
    Is predicted physics enabled by default in 1.0? It's not quite clear to me from the docs if there's something I need to do.

    Or perhaps I'm doing something wrong. I'm trying to fire some projectiles that have a physics body+shape and are owner predicted. When fired on the client, the projectile seems to not move until it's fired on the server (I put some simple logging in and increased simulated RTT to determine this), at which point it snaps forward on the client to where it is on the server.

    Any ideas what might be wrong here? I can provide more info if needed.
     
  2. Occuros

    Occuros

    Joined:
    Sep 4, 2018
    Posts:
    284
    From the manual:

    In order to to use physics simulation for predicted ghosts you must enable it by creating a singleton with the PredictedPhysicsConfig component. The singleton must exist on both the client and server with compatible values (same simulation frequency). The component lets you specify the physics tick rate as a multiple of the NetCode simulation tick rate, so you can run for example a 60Hz game simulation with 120Hz physics simulation.

    Which can be found in the physics section:
    https://docs.unity3d.com/Packages/com.unity.netcode@1.0/manual/physics.html

    The component is now named “NetCodePhysicsConfig” (if I remember correctly).

    you can verify that physics prediction is working if you have the physics systems inside the prediction on the client side.

    If that is still unclear let me know.
     
  3. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,626
    This has confused me a bit because it seems to me to always move the physics now unconditionally?

    Code (CSharp):
    1. [WorldSystemFilter(WorldSystemFilterFlags.ClientSimulation | WorldSystemFilterFlags.ServerSimulation)]
    2. [UpdateInGroup(typeof(InitializationSystemGroup))]
    3. public partial class PredictedPhysicsConfigSystem : SystemBase
    4. {
    5.     protected override void OnUpdate()
    6.     {
    7.         MovePhysicsSystems();
    8.         var physGrp = World.GetExistingSystemManaged<PhysicsSystemGroup>();
    9.         physGrp.RateManager = new NetcodePhysicsRateManager(physGrp);
    10.         World.GetExistingSystemManaged<InitializationSystemGroup>().RemoveSystemFromUpdateList(this);
    11.     }
    So my question is more, how do I make it not predicted physics :confused:
     
  4. Occuros

    Occuros

    Joined:
    Sep 4, 2018
    Posts:
    284
    Interesting, maybe they move it now always as you also have a client only physics system with the proxy?

    but I haven’t looked deeper into that part just yet.

    does it cost any performance if none of the ghost entities are predicted?
     
  5. timjohansson

    timjohansson

    Unity Technologies

    Joined:
    Jul 13, 2016
    Posts:
    473
    What do you mean by not predicted physics in this case, what are you trying to do?

    The way it works in 1.0 is that any predicted ghost with non-static physics will predict the physics simulation of that ghost. Any interpolated ghost with physics will update on the server but will be kinematic on the client since the client cannot move it. So the way to enable not-predicted physics is to not have any predicted ghosts with physics simulation.

    If you do not have any predicted ghosts with physics velocity the physics group will not run for re-simulated ticks on the server so it doesn't give you a big performance hit.

    If you want some client only physics for visual effect (debris, particles etc which does not exist on the server) you need to setup a secondary physics world to simulate them since they cannot affect the physics simulation of ghosts.

    This was actually the only setup that really worked correctly in older version too, which is why we made it the default.
     
    Occuros likes this.
  6. sirwhatevers

    sirwhatevers

    Joined:
    Aug 25, 2017
    Posts:
    33
    Thanks for all the info. It looks like the physics systems are indeed running in the prediction group, so maybe I'm doing something wrong.
     
  7. timjohansson

    timjohansson

    Unity Technologies

    Joined:
    Jul 13, 2016
    Posts:
    473
    They will run in the prediction group. But unless you have predicted ghosts with physics they will not run for every prediction tick on the client. They will just run the same number of times they would if they were not in the prediction group - which depends on the fixed rate.
     
  8. sirwhatevers

    sirwhatevers

    Joined:
    Aug 25, 2017
    Posts:
    33
    I did some debugging and it looks like the velocity is getting forced to 0 for some reason on the client.
    client:
    upload_2022-10-13_11-50-59.png

    server:
    upload_2022-10-13_11-52-43.png

    log:
    upload_2022-10-13_11-52-1.png
    upload_2022-10-13_11-54-36.png
     
  9. sirwhatevers

    sirwhatevers

    Joined:
    Aug 25, 2017
    Posts:
    33
    I have some additional info. I just learned how to use the Journaling window.
    upload_2022-10-13_13-32-7.png

    upload_2022-10-13_13-32-53.png
     

    Attached Files:

  10. CMarastoni

    CMarastoni

    Unity Technologies

    Joined:
    Mar 18, 2020
    Posts:
    774
  11. sirwhatevers

    sirwhatevers

    Joined:
    Aug 25, 2017
    Posts:
    33
    Good to know, thank you! Is there a place I should look for known issues?
     
  12. Occuros

    Occuros

    Joined:
    Sep 4, 2018
    Posts:
    284
    Could this issue also affect kinematic objects which are moved byphysics (using
    PhysicsVelocity.CalculateVelocityToTarget).

    As we experience less smooth behavior currently compared to 0.53 on player input moved objects. Could this be related?
     
  13. CMarastoni

    CMarastoni

    Unity Technologies

    Joined:
    Mar 18, 2020
    Posts:
    774
    In the context of multiplayer or in general?

    It should affect only replicated (kinematic or not) ghosts. For non-replicated entities, the PhysicsVelocity is reset to zero only if PhysicsMassOverride.SetVelocityToZero is set.

    For Replicated Kinematic Character in particular, that may cause some little "jittery/less smooth" motion as you described.
     
    Occuros likes this.
  14. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,626
    Sorry for the slow reply. I went on holidays and came back to my house being flooded by a river...

    So I've been busy ^ and I haven't tested enough to say for certain this is how it works, but I believe my problem stems from the fact I only use interpolated ghosts and no prediction.

    In this case I can't see why my client only physics objects need to exist in a secondary physics world instead of all existing in the same world. I don't want the overhead of running 2 physics simulations for no reason - I was already having problems with physics.
     
    Last edited: Oct 27, 2022
  15. CMarastoni

    CMarastoni

    Unity Technologies

    Joined:
    Mar 18, 2020
    Posts:
    774
    They are in the same world, they just use a PhysicsIndex shared component to group them. It is a "logical" separation
     
  16. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,626
    I'm trying to figure out if this is required if I'm using interpolated only or if it's possible to avoid and use a single physics index
     
    Last edited: Oct 27, 2022
  17. CMarastoni

    CMarastoni

    Unity Technologies

    Joined:
    Mar 18, 2020
    Posts:
    774
    You only need a client-only physics "world" if you need to have some physics that run only on the client and you don't need that to rollback or predicted in any way.
    Otherwise, there is no reason for two indices. The use of interpolation or extrapolation does not requires any extra world.
     
  18. hxhloveunity

    hxhloveunity

    Joined:
    May 27, 2022
    Posts:
    32
    how to collide with different world (Physics Predict World And Client Only World), In document, say use PhysicsProxyGhostDriver component, but I dont see this componet in network package。
     
  19. CMarastoni

    CMarastoni

    Unity Technologies

    Joined:
    Mar 18, 2020
    Posts:
    774
    We a re updating the docs. The logic is changed a little bit.

    You just need to add a `CustomPhysicsProxyAuthoring` authoring to ghost prefab. That will create a "proxy" physics object in the client-only world that will collided with the client-only physics objects.
     
  20. optimise

    optimise

    Joined:
    Jan 22, 2014
    Posts:
    2,029
    What has been changed at 1.0? At 0.51 I can trigger physics but it's no longer working at 1.0. What should I change to get back the same bahavior?
     
  21. CMarastoni

    CMarastoni

    Unity Technologies

    Joined:
    Mar 18, 2020
    Posts:
    774
    The UnityPhysics package has an issue in 1,0-exp.8 that has been fixed in the latest update we release some day ago.
     
  22. optimise

    optimise

    Joined:
    Jan 22, 2014
    Posts:
    2,029
    I know the bug fix u mention but I'm saying another issue. Currently at my game project, I have pickup that using trigger physics to detect when player go and pick it. The pickup is working at 0.51 but not working anymore at 1.0. Any idea why?
     
  23. CMarastoni

    CMarastoni

    Unity Technologies

    Joined:
    Mar 18, 2020
    Posts:
    774
    Ah!! Ok, you didn't say anything like that :)
    That is a very good question and I honestly need to check. They should, if they don't, it is a problem.
    Are you using Collision Event for that ?
     
  24. optimise

    optimise

    Joined:
    Jan 22, 2014
    Posts:
    2,029
    At Physics Shape authoring there's Collision Response option, Raise Trigger Events is selected
     
  25. CMarastoni

    CMarastoni

    Unity Technologies

    Joined:
    Mar 18, 2020
    Posts:
    774
    Alright, so "collision" events. Is the even not triggered on the server or the client, or both?