Unity 3D v4.3 was released recently, and it brought with it a bunch of cool new features.

We develop mostly 2D Games, so one of the new features we were most excited about was the integration of a native 2D Mode Toolset.

With this 2D Mode, the Unity3D team included Box 2D, a 2D Physics engine that has already been around for a couple of years.

Obviously using the 2D Physics engine for 2D Games will be faster. But how fast?

We decided to create a couple of demos and profile them to measure the difference between both Physics engines in a 2D game environment.

All of these demos are running on a mobile device ( HTC One ). Please note that all measurements are done with the profiler connected to the device over WiFi.

Like all profilers, some overhead is added to the performance, and also Deep Profiling was always selected, which added a greater overhead.

But because we are doing comparison tests always in the same environment, that overhead becomes irrelevant.

The first demo simply drops ~300 boxes on a closed container.

Figure 1 – Profiler on 3D Physics Engine

This first shot shows the profiler results when using the already existing 3D Physics Engine.

It has an average of ~400ms spent on the Physics Engine, once all 300 boxes are instantiated.

Figure 2 – Profiler on 2D Physics Engine

On this second shot, we are using the newly included Box 2D engine. It has an average of ~70ms spent on the Physics Engine.

These results are really quite good. What they mean is that in a 2D Environment, using the proper 2D Physics engine is ~5x faster than using the 3D one.

On the second test, a pyramid with a bottom size of 35 boxes is created and then blasted with some cannon balls.

For this test, we will be analyzing the average frame rate just for the sake of showing different kinds of results.

Figure 3 – Average frame rate on 3D Physics Engine

Figure 4 – Average frame rate on 2D Physics Engine

For the 3D Physics Engine simulation, we have an average of ~13 FPS. As for the 2D Version, we have an average frame rate of ~47 FPS. This shows a ~4x increase in performance.

Both demos are relatively similar on what they are testing, and both their results are really quite exciting.

With 4x performance gain (worst test) means that we will have 4x more CPU time on our hands to add more and better features!

So you guys can also feel the power of the new 2D Physics engine, we decided to publish a Web Player version.

Because you are going to run on faster machines than a mobile device, we made some changes on the demos.

On the first demo, boxes will fall until the average frame rate drops down under 30 FPS.

On the second demo, we increased the the pyramid bottom size to 55, creating a total of 784 blocks.

For simplicity, we also decided to merge both demos into one, where you can toggle what kind of test you want to perform.

Here are some results running the demo on a Mac Mini with the current specs:

  • 2.3GHz Quad-core I7
  • 4GB of DDR3 SDRam

Figure 5 – Maximum instances on 2D Mode

Figure 6 – Maximum instances on 3D Mode

Conclusion

It’s really great that Unity3D gave us this new set of tools. You can see from all the tests above, and you can also check for yourself using our demo, that it really makes a big difference using the 2D Physics engine when developing 2D Games.

The process of building a project from scratch or updating your current one to Box 2D is extremely easy. All the tools, collision matrix configuring, etc., are similar to how you are used to.

Scripting-wise, it is also really similar to how you work with both engines.

For example, adding a force to a game object:

  • [2D] rigidBody2D.AddForce( … )
  • [3D] rigidBody.AddForce( … )

So if you are developing 2D games today, there is no excuse for starting to use the new Physics engine. You’ll get better performance, meaning you’ll have more CPU time at your disposal to create even better games.

Also read: Unity 3D Best Practices