Havok to Unity Physics and back again?

Forgive me if I am being obtuse, but based on the post about havok physics, it seems like unity DOTs physics and Havok will be interchangeable in terms of data? it also seems the examples are built to support both?

So my actual question: Does that also mean that effectively code working for one will work for the other, allowing you to swap between the two later in a projects lifecycle? Or is it an up front decision?

Yes, Unity and Havok are two interchangeable simulation backends working on the same ECS component datas.
If you interact via the ECS data then the code should absolutely work via both (if not please tells us and we will fix that). One caveat is that forces and/or material properties tweaked for one backend might need re-tweaked for the other.

Depending on your project you may want to pick one over the other up front. If massive stable stacks are what you are looking for (Throw Cubes into Brick Towers To Collapse Them by nothke), then you’ll want to run with the Havok Physics backend from the get-go. If network determinism is the focus then the stateless nature of the Unity Physics simulation backed may be the best choice. If you only need to perform queries in a mostly static environment then you might not need either simulation backend.

Is it possible to tell on per object basis which physics to use?

You can technically have as many PhysicsWorlds as you like, each using whichever simulation backend you like. Rigid bodies in each world can only collide with those from the same world.

This is not exposed to the ECS Systems or the UI right now - there is one physics world and one simulation backend as far as ECS is concenered.

But you could do it yourself if you really wanted. Thinking aloud:

  1. Modify or duplicate BuildPhysicsWorld to query for presence of some custom component in the entity query, and produce 2 PhysicsWorlds
  2. Modify or duplicate StepPhysicsWorld to step both worlds, with the approprate backends
  3. Modify or duplicate ExportPhysicsWorld to write the new entity transforms from the results of both worlds

You could duplicate the static bodies in both worlds if desired, or even have some of the dynamic bodies appear as static in the the other world. The thing you can’t do is have a dynamic body appear in both worlds, because you will end up having to choose one of the two conflicting resulting transforms to write back to the entity.

I actually expect these use cases of mixing multiple simulations will come up more as DOTS Physics evolves. Its a bit early to know exaclty what that will look like though…

Multiple worlds has come up before. The common reason to have them is when you have a lot of static colliders and either a few dynamic ones or even a few static that come and go. Without partitioning rebuilding is a huge hit. Worlds aren’t the only way for all use cases, but they do work well.

I think what some people didn’t think of is once you make colliders as cheap as they are in Unity.Physics, people would find new uses for them. Like we use the terrain collider and we have colliders on all of our vegetation in Vegetation Studio. Some scenes we have over 200k colliders. They are just that cheap really once you sort out how to partition stuff so rebuilding doesn’t kill you.

1 Like