Frame Rate

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

EDIT 3: Solution here:
https://discussions.unity.com/t/780211/7

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:

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.

1 Like

Thanks I literally have nothing between begin and end FixedStepSimulationSystemGroup ???

You can use:

[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:

var buildPhysicsWorld = World.GetExistingSystem<BuildPhysicsWorld>();
buildPhysicsWorld.Enabled = false;

And then calling:

var buildPhysicsWorld = World.GetExistingSystem<BuildPhysicsWorld>();
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. ~~

1 Like

Cool , I am confused as to where to disable the system though??

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:

[UpdateInGroup(typeof(FixedStepSimulationSystemGroup))]
public class PhysicsMigrationSystem : SystemBase
{
    protected override void OnCreate()
    {
        // Disable Systems Here.
    }

    protected override void OnUpdate()
    {
        // Update Systems Here.
    }
}

But I haven’t actually tested that.

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

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://discussions.unity.com/t/780211/7

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. :wink:

1 Like

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.

4 Likes

This worked well. thanksvery much… trying your other methods helped me learn more that way too.

1 Like

When? … The stutter is brutal. :slight_smile:

1 Like

I don’t have a hard time but aiming for with the next couple of weeks. I’ll update when I know more.

4 Likes