Low-level 2D Physics in Unity 6.3

What is it?

  • Low-level 2D Physics based upon the latest Box2D v3 is now available in Unity 6.3 beta

  • A new API that empowers developers with direct access to a powerful new physics system, providing the ability to write their own components or their own full physics API offering (asset store, custom components for games etc).

Features:

  • Works completely independent of GameObjects and Components but has lots of support to work with them (Transform writing, Transform Planes etc)

  • Supports multiple 2D Transform planes i.e. XY, XZ, ZY.

  • Multiple independent and isolated World Support with automatic and parallel simulation, fully configurable.

  • Highly parallelised out-of-the-box. Will scale up to 64-cores if available on a device. Can perform world simulations in parallel too.

  • A majority of the API can be called in a C# Job away from the main-thread.

  • All the API is struct based. All objects are struct handles therefore work with Unity native containers for DOTS.

  • Unlimited number of bodies, shapes and joints created in a world. Batch creation and destruction available.

  • Rich and powerful query system (works in C# Jobs too).

  • Geometry utilities for layer-based composition and fragment/slicing destruction.

  • Full debug drawing system which will also work in development player builds.

Support / Help

  • The “PhysicsExamples2D” repo has been split into “Legacy” (existing physics) and “PhysicsCore2D” (new physics).

    • There’s now a Sandbox project here which can be built for players too. It demonstrates various features of the new API with more examples being added regularly.

    • In addition, there’s also a “Primer” project here which hosts a set of examples showing how to get started with the new API. It also has a comprehensive overview in the README.

    • Finally, there’s an example “Extras” package which is designed as a helping hand in using the new physics using features only, it is not a production ready and verified package. However, it does encapsulate all the main physics objects (bodies, shapes, chains, joints etc) with components you can add to GameObjects and configure in the inspector. It also features Editor tooling to allow editing of shape geometry directly in the scene. The package provides an excellent example of how you can write components using the new physics for your own purposes.

  • A new manual is currently being worked on dedicated to this new API which will cover all aspects of its use.

The first draft of the scripting API is already public here (all API is in the namespace “UnityEngine.LowLevelPhysics2D”)

:double_exclamation_mark: Important Note :double_exclamation_mark:

  • No changes have been made to the existing 2D physics components. This API is completely isolated from them so is fully backwards compatible; we expect no changes in existing projects.

Future Plans:

  • We are planning to replace the existing components with this new API and are working on a migration plan to deal with both API and behavioural changes related to integrating a new physics system. We will be using the exact same public API available here to achieve this (100% dog-fooding)!

  • User components written using this API will be fully compatible and interact with our own components due to the nature of the new API.

32 Likes

Can you confirm that there’s no dependencies that force it and other packages being included when using the high-level physics only?

Highly concerned about having to “bloat” web builds with 2 physics APIs+dependencies when only one is used. That is, until the high-level API calls the low-level one consistently.

1 Like

It doesn’t force any packages being included. It has no external dependencies. There’s a code-size overhead until we fully move over but when we do that, it’ll be a heck of a lot smaller overall. There should be zero runtime overhead.

There’s also a “Bypass LowLevel” option too in the settings that completely bypasses it. I doubt you’d need that but can use it.

We’re also investigating moving it to a new internal module so you can disable it that way too which is a lot simpler.

4 Likes

I just wanted to say that after a first glance at readme etc., this looks great. Having this would’ve saved A LOT of weird hacks and performance tricks on my just about to be finished game. Great work!

1 Like

Can I obtain this fixed-point number math library of box2d v3?

Box2D v3 doesn’t have a fixed-point math library. Sorry, I have no idea to what you’re referring to.

Maybe you’re asking about Determinism, rather than asking “how to obtain a fixed-point math library”?

yes fixedpoint+burst

With the fixed-point number mathematics library, multi-platform determinism can be achieved

Box2D: FAQ Box2D has cross-platform determinism as of version 3.1.

Box2D doesn’t use fixed-point. Burst works with C# code, Box2D is C. Burst isn’t relevant to Box2D/Determinism.

You don’t need fixed-point to perform multi-platform determinism. Please read the link I provided above which is from Erin Catto himself discussing why you don’t need fixed-point.

I integrated Box2D into Unity, I’m very familiar with what it provides. :wink:

Please:

  • Follow the link I provided for you which gives you details on how it works (not fixed-point)
  • Try the samples
  • We’re as deterministic as Box2D is however it’s not something that has been widely tested in Box2D yet and we’re not guaranteeing that for now in Unity although it’s performing well so far. With more testing on various devices and potential tweaks, we might be able to offer some form of guarantee.
4 Likes

I have a need for a school of fish to move in clusters. If multiplayer games require synchronization, using state synchronization will cause huge network pressure. However, if there is a fixed-point number math library, it will be much easier to handle

Feel free to use a fixed-point math library. It’s not the role of a physics engine to provide that though. It doesn’t require it.

Box2D has roll-back determinism planned too which will help with networking scenarios.

1 Like

hhhh, this is really hard. I can’t find a fixed-point number math library with as rich functions as Unite.mathematics, so I hope the official can provide a math library, not caring about performance

Maybe ask around on another thread, it’s unrelated to the new 2D physics here.

Thanks.

Do you need the individual location of the fish to be synchronous?
A typical way to have swarms of fish be synchronous in e.g. a fishing game is to have a swarm algorithm that essentially follows one invisible core. Sometimes called “pseudo boyds”.
Then only those cores need to be synced across the network.

As for the topic, I can only agree this looks very interesting!
Just in time for a physical soft body inventory system I want to build…

Fun fact the visual renderer renders in multiple types of editor tabs.
I managed to get physics simulation matching from scene view into the Tile Map palette.

On the right side in the center, you can see the capsule body being rendered on the Tile Palette window. Got bored after this screen shot and started making a mario style minigame in my tile palette window.

4 Likes

That has the same vibe of people who make Doom playable on a coffee machine xD

2 Likes

Thanks for the heads-up. Now I don’t know whether to fix that or leave it be. :wink:

EDIT: I’ve fixed the issue and should anyone want to track it, you can find it here: Unity Issue Tracker - 2D Physics Renderer renders in all camera window types

The problem is that the fish have obstacle avoidance test and multi-thread to calculate these, use the NativeParallelMultiHashMap to block, is difficult to guarantee the same, different computer and lack of fixed-point math library, have a number of fixed-point math library can try to put him into a frame synchronization system