#Invoke UnityPhysics sim programmatically?

1 messages · Page 1 of 1 (latest)

umbral lily
#

I'm trying to build a physics network reconciliation system with UnityPhysics, so I have to be able to invoke the physics simulation multiple times per frame, and also ensure the physics simulation doesn't run, unless I tell it to programmatically. For regular PhysX, this would look like...

    private void SwitchToManualPhysicsSim()
    {
        Physics.simulationMode = SimulationMode.Script;
    }

    private void SimulatePhysics(float deltaTime)
    {
        Physics.Simulate(deltaTime);
    }

What's the ECS equivalent of this? Bonus points if I can do this from a MonoBehaviour script (I know this isn't best practise, will refactor into ECS later if I can just get a barebones system working for now)

umbral lily
#

So I've tried

var physicsSystem = Unity.Entities.World.DefaultGameObjectInjectionWorld.GetExistingSystem<FixedStepSimulationSystemGroup>();

        for (int i = 0; i < 2000; i++)
        {
            Debug.Log("Sim phys " + i);
            physicsSystem.Update(Unity.Entities.World.DefaultGameObjectInjectionWorld.Unmanaged);
        }

This certainly hitches the framerate, but I would expect to see all my physics object "jump forward", and this doesn't happen, the game pauses for a fraction of a second, and then continues as if no additional physics simulations occurred.

Am I getting some syntax wrong here? I have a feeling it's using some internal delta time (time of last physics sim), which will ofc be 0 if I'm invoking it repeatedly like this... maybe there's some way of overriding this delta time?

split gazelle
#

doesn't matter how many times you call update

#

physics runs at a fixed rate

#

if time hasn't passed the system won't update anymore

#

you'd need to remove the rate manager from FixedStepSimulationSystem

#

so it no longer ran at a fixed rate and you could control it instead

umbral lily
#

That sounds like a promising breadcrumb! Not immediately sure how to do that, but will investigate and report back!

split gazelle
#

RateManager= null