Physics for ECS: Havok Physics for Unity and Unity Physics
Tutorial
·
intermediate
·
+10XP
·
25 mins
·
(54)
Unity Technologies

In this tutorial, you’ll learn about two advanced physics solutions available for projects that use Unity’s Entity Component System (ECS) framework: Havok Physics for Unity and Unity Physics.
Important: This tutorial only applies to Unity 2022.2 Tech Stream and beyond, which will be reflected in the tutorial version in early 2023.
Languages available:
1. Overview
Different projects have different needs when it comes to simulating physics. Unity has a range of different physics engines that you can choose between to meet the needs of your project. In this tutorial, you’ll learn about two advanced physics solutions available for projects that use Unity’s Entity Component System framework: Havok Physics for Unity and Unity Physics.
By the end of this tutorial, you will be able to do the following:
- Describe the key benefits of Havok Physics for Unity and Unity Physics.
- Explain the relationship between Unity Physics and Havok Physics for Unity.
- Identify situations where physics solutions for ECS are the right fit for a project.
Important: This tutorial is an introduction to physics solutions for ECS in Unity for users with an intermediate level of experience and beyond, as part of DOTS. DOTS is Unity’s Data-Oriented Technology Stack, a suite of data-oriented technologies for advanced users who need to make complex projects with highly optimized performance. If you want to learn more about DOTS itself, we recommend the newly-released DOTS Guide (GitHub).
2. Physics in Unity
Before you learn more about advanced physics solutions in Unity, let’s review some fundamentals.
At a very high level, physics in real-time experiences refers to the properties of objects and how they respond to forces. Some projects aim to simulate physics in a way that replicates the real world — for example, a game with the goal of replicating the experience of driving a racing car as accurately as possible. Other projects take a more flexible approach and implement rules of physics in their game that deviate from the real world, such as unexpected behavior when objects collide or impossible leaps that the player character can make.
The way that you simulate physics in your Unity project is determined by a specific physics engine. Just as a real-time engine is a framework for creating experiences like games and simulations, a physics engine is a framework that integrates into the game engine so that you can implement laws of physics in your project.
In Unity, there are a number of different physics engines that you can choose from depending on the specific project that you’re working on.
Physics engines for object-oriented projects
If you’re working on an object-oriented project, you can use either the built-in 3D physics engine or the built-in 2D physics engine.
Physics engines for data-oriented projects
Unity’s Entity Component System (ECS) organizes your project in a data-oriented way, as opposed to the traditional object-oriented way. If you’re working on an ECS-based project, you’ll need to install an ECS-compatible physics package. There are currently two packages available:
- Unity Physics: An ECS-compatible physics engine that will simulate physics in any ECS project. Unity Physics is available for users with any Unity edition.
- Havok Physics for Unity: An implementation of the Havok Physics engine for Unity that you can use as an extension of the Unity Physics package. You can use Havok Physics for Unity with a Unity Pro or Unity Enterprise subscription.
3. Basics of DOTS physics in Unity
The Data-Oriented Technology Stack (DOTS) can provide experienced creators with considerably improved performance for games or applications that display a significant number of things (for example, a large ball pit simulation where each individual ball is a separate thing which needs to be displayed). DOTS will have a reduced impact on the performance of projects which deal with fewer items.
The Entity Component System
The Entity Component System is the core of the Unity Data-Oriented Tech Stack. This system has three principal parts:
- Entities: The entities, or things, that populate your application. An entity is essentially an ID — it identifies which pieces of data belong together. Entities don’t have their own behavior or data.
- Components: The data associated with Entities, organized by the data itself rather than by entity. This approach to organization is one of the key differences between an object-oriented and a data-oriented design.
- Systems: The logic that transforms the component data from its current state to its next state. For example, a system might use an entity's velocity multiplied by the time interval since the previous frame to update the positions of all moving entities.
ECS physics workflow
Let’s review the high-level workflow for physics in projects that use ECS:
- When you work on a project using ECS, you can create GameObjects in the Unity Editor as you would for any other project and then use baking to transform the GameObject data into Entities written to Entity Scenes.
- In the Entity conversion process, you convert information from Physics authoring components (and any joint scripts) into entity data.
- The Build Physics World system converts that physics data into a different format that’s optimized for runtime and a large number of random access queries.
- You can then select the physics engine that you want to handle the physics data: Unity Physics or Havok Physics for Unity.
- Once the physics engine has done its work, the Export Physics World system takes the physics data that’s been optimized for runtime and converts it back to ECS data.

4. Deepen your understanding of the physics for ECS workflow
If you are a more experienced user who wants to learn about the DOTS physics workflow in more detail, you can start with these videos taken from the Unite Copenhagen 2019 talk on Havok Physics in Unity.
Important: These videos are for advanced users. You do not need to watch these videos to gain a high-level understanding of the physics engine options for projects that use ECS.
Physics for ECS — ECS overview
This video contains a more detailed overview of the process outlined in the previous step.
Physics for ECS — Data
This video outlines the data that is input to and output from the chosen physics engine for a project that uses ECS.
5. What are the differences between the ECS-compatible physics engines?
You’ve now established that there are two different physics engines that you can choose between for projects that use ECS: Havok Physics for Unity and Unity Physics. Both of these physics solutions are based on Unity’s ECS framework, so they use the same data protocol. This means that you can transition your projects between the two different physics engines without having to rebuild your content or game code.
Whether you’re using Unity Physics, Havok Physics for Unity, or both together, the unified data protocol allows you to author once and then simulate physics using any ECS-compatible physics system.
Unity Physics
Unity Physics is built on Unity’s ECS framework. It is network-ready, completely customizable, and built for performance out of the box. Unity Physics uses the Burst compiler and Unity’s C# Job System to optimize the performance of your physics simulations across a range of devices.
Unity Physics is currently in Preview release and available via the Package Manager. It is compatible with Unity 2022.2 and later versions. You can use Unity Physics for free regardless of your Unity subscription.
Havok Physics for Unity
Havok Physics for Unity is a high-end solution for creators who need to produce complex physics simulations. It is written using the same ECS framework as Unity Physics but includes the functionality and performance of the closed source, proprietary Havok Physics engine. The Havok Physics engine is written in native C++.
Havok Physics for Unity requires a Unity Pro or Unity Enterprise subscription.
Havok Physics is heavily optimized for simulating physics in graphically-intense games, which often include intricate scenes with lots of physical interaction. The benefits of using Havok Physics for Unity include the following:
- Stable stacking of physics bodies.
- Minimal artifacts where there are fast-moving physics bodies.
- More controlled behavior in general, especially when you are working with non-optimized collision geometry.
In the following video, the team explains how Unity and Havok partnered together to create Havok Physics for Unity on top of Unity’s ECS framework.
6. Evaluate the difference between the ECS-compatible physics engines
Unity’s DOTS Samples repository includes a Physics Samples project that you can use to test both Unity Physics and Havok Physics for Unity (if your edition includes access to it).
Follow these instructions to evaluate the difference between the physics engines:
1. Install Unity 2022.2 if you haven’t already done so.
2. Download the Physics Samples project and open the UnityPhysicsExample project in the Editor.
3. Install the Havok Physics for Unity package if you haven’t already done so.
4. In the Project window, go to Assets > Tests Pyramids and open the Pyramids test scene.
5. In the Hierarchy, select the Physics Settings GameObject.
6. In the Inspector, go to the Physics Step component and check that the Enable Contact Solver Stabilization Heuristic setting is disabled.

You can use the Contact Solver Stabilization Heuristic in Unity Physics for stable stacking based on contact velocity correction. When this property is enabled in non-stacking situations, non-Physical behavior may be introduced to your project.
7. Select Play to run the simulation scene using the Unity Physics engine, then select it again to stop the simulation and reset the pyramid stack.
8. In the Hierarchy, expand the foldout for the Physics Scene Basic Elements GameObject, then select the Physics Settings child GameObject.
9. In the Inspector, go to the Physics Step component and find the Simulation Type property. Set this property to Havok Physics.

Note: You can also switch the physics engine at runtime.
10. Select Play to run the pyramid simulation again.
11. In the Game view, you can do the following:
- Left-click to select and drag dynamic GameObjects.
- Right-click and drag to change your view in the Game view.
Observe that the simulation is more stable than it was in Unity Physics without the Contact Solver Stabilization Heuristic enabled, due to the use of simulation caches in Havok Physics for Unity.
Extend your evaluation
The difference in behavior you observed in this step can also be found in the ComplexStacking scene (which you can find in Assets > Tests > Stacking). You can observe this difference when you apply different friction values on stacking objects. In the ComplexStacking scene example, the default friction values are 0.4, 0.2 and 0.0 from closest to furthest. While Havok Physics gives expected behavior in all cases, you will notice that solver stabilization significantly improves behavior of Unity Physics but some stacking instabilities still exist.
7. Next steps
Now you know about the basics of the physics for ECS. There are also a range of different resources available to help you continue your learning:
- To develop your understanding of DOTS in general, start with the new DOTS Guide on GitHub and the DOTS Best Practices course.
- To learn more about Unity’s DOTS physics solutions, watch the full Unite Copenhagen 2019 overview of Havok Physics for Unity (YouTube).
- To get started working with physics for ECS, explore the Unity Physics and Havok Physics for Unity package documentation. You can also connect with other creators in our physics for ECS forum.