Search Unity

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

Frame Rate

Discussion in 'Physics for ECS' started by shotoutgames, Aug 8, 2020.

  1. shotoutgames

    shotoutgames

    Joined:
    Dec 29, 2013
    Posts:
    283
    What is the proper way to handle using unity dots physics?
    I am using Physicsvelocity - just modifying the Value directly for player movement and jump
    I made a build and ran it on a laptop and the player just slows down a bunch (not the framerate)
    Still learning.
    Thanks
     
  2. NotaNaN

    NotaNaN

    Joined:
    Dec 14, 2018
    Posts:
    325
    EDIT 3: Solution here:
    https://forum.unity.com/threads/how...ependent-physics-in-dots.844252/#post-5601655

    If your framerate is Identical, then I assume that FixedStepSimulationSystemGroup is running at the standard frequency (60 Hz) without missing any beats.

    Are you one-hundred percent sure that your code for movement — specifically the velocity-manipulation part — is within FixedStepSimulationSystemGroup? If your code is in the standard SimulationSystemGroup and you were just doing:
    Code (CSharp):
    1. PhysicsVelocity.Linear += new float3(0.05f, 0, 0);
    For example. You're going to run into the issue you are experiencing.


    My rule of thumb is this: Always put all code other than Input Detection and Presentation Anything in a Fixed-Stepped area. This means that you will need to buffer your inputs from SimulationSystemGroup for them to be usable.

    EDIT: Another thing that I'm assuming is that Unity Physics is now using FixedStepSimulationSystemGroup instead of SimulationSystemGroup. I have not read that they have made the switch, but I am assuming they have. If not, then the OP will need to move the Physics Systems into FixedStepSimulationSystemGroup.

    EDIT 2: After sifting through the official changelog I have yet to find any indication that Unity Physics has made the switch to FixedStepSimulationSystemGroup, unless this change was made internally without it being documented.
     
    Last edited: Aug 10, 2020
    shotoutgames likes this.
  3. shotoutgames

    shotoutgames

    Joined:
    Dec 29, 2013
    Posts:
    283
    Thanks I literally have nothing between begin and end FixedStepSimulationSystemGroup ???
     
  4. NotaNaN

    NotaNaN

    Joined:
    Dec 14, 2018
    Posts:
    325
    You can use:
    Code (CSharp):
    1. [UpdateInGroup(typeof(FixedStepSimulationSystemGroup))]
    To schedule your systems to run within the specified group.

    Do note, that apparently Unity Physics is not updating physics within FixedSimulationSystemGroup yet (citation needed).
    You will need to move it manually to FixedSimulationSystemGroup to get pleasing results.


    As for how to move Unity Physics to the FixedSimulationSystemGroup, it should (hopefully) be as simple as doing:
    Code (CSharp):
    1. var buildPhysicsWorld = World.GetExistingSystem<BuildPhysicsWorld>();
    2. buildPhysicsWorld.Enabled = false;
    And then calling:
    Code (CSharp):
    1. var buildPhysicsWorld = World.GetExistingSystem<BuildPhysicsWorld>();
    2. buildPhysicsWorld.Update();
    In the OnUpdate method of a new system of your choice that updates within the FixedSimulationSystemGroup.
    You will need to do this for every System within Unity Physics, and you will need to update them in the proper order or bad stuff is gonna happen.

    ~~ Important Note: What I have describe above is a serious hack (and is also untested). You should not be using the Enabled property on ComponentSystemBase like this. ComponentSystemBase.Enabled is meant for toggling a system on and off in the Entity Debugger and should only be used for debugging purposes. ~~
     
    shotoutgames likes this.
  5. shotoutgames

    shotoutgames

    Joined:
    Dec 29, 2013
    Posts:
    283
    Cool , I am confused as to where to disable the system though??
     
  6. NotaNaN

    NotaNaN

    Joined:
    Dec 14, 2018
    Posts:
    325
    This one's up to you, but ideally you should only disable the system once — preferably somewhere obvious.
    If you have a script that defines a lot of SystemGroups for your own personal use, I would put it there.

    It should be something like:
    Code (CSharp):
    1. [UpdateInGroup(typeof(FixedStepSimulationSystemGroup))]
    2. public class PhysicsMigrationSystem : SystemBase
    3. {
    4.     protected override void OnCreate()
    5.     {
    6.         // Disable Systems Here.
    7.     }
    8.  
    9.     protected override void OnUpdate()
    10.     {
    11.         // Update Systems Here.
    12.     }
    13. }
    14.  
    But I haven't actually tested that.
     
  7. shotoutgames

    shotoutgames

    Joined:
    Dec 29, 2013
    Posts:
    283
    Looks like I was on the right track thanks again..Seems to have helped..for starters the the player is moving fasters in the editor. It still shows the physics systems as part of the simulation group in the entity debugger though. Is this expected?

    Edit: If I turn off the systems they remain inactive even after I run them in update? so no movement - I do however notice the change when I don't disable them first
     
    Last edited: Aug 9, 2020
  8. NotaNaN

    NotaNaN

    Joined:
    Dec 14, 2018
    Posts:
    325
    Yeah, that sounds right.
    All we're doing is disabling standard updating of the system and then manually telling it to run from another system. Unity doesn't know about all that, which is why they are still placed within SimulationSystemGroup in the debugger. So that should be fine.

    Oh boy. That means its not working.

    Just did some research (shoulda done this first before I started to try and assist you — oh well), I found a thread that should solve your issue.

    https://forum.unity.com/threads/how...ependent-physics-in-dots.844252/#post-5601655

    Apparently there is a FixedRateUtils Extension specifically for migrating SimulationSystemGroup to FixedStepSimulationSystemGroup. I am yet to try it myself, but I'm assuming that it should do just the trick. ;)
     
    shotoutgames likes this.
  9. steveeHavok

    steveeHavok

    Joined:
    Mar 19, 2019
    Posts:
    481
    We are aiming to get all the Physics systems (and samples) moved into the FixedStepSimulationSystemGroup for the next update. We are also putting the final touches to the equivalent of the legacy Rigidbody Interpolate/Extrapolate options as well.
     
  10. shotoutgames

    shotoutgames

    Joined:
    Dec 29, 2013
    Posts:
    283
    This worked well. thanksvery much.. trying your other methods helped me learn more that way too.
     
    NotaNaN likes this.
  11. shotoutgames

    shotoutgames

    Joined:
    Dec 29, 2013
    Posts:
    283
    When? ... The stutter is brutal. :)
     
    petarmHavok likes this.
  12. steveeHavok

    steveeHavok

    Joined:
    Mar 19, 2019
    Posts:
    481
    I don't have a hard time but aiming for with the next couple of weeks. I'll update when I know more.