(v0.50) DOTS Tutorial - Build a Multiplayer AR app
  • What is the Purpose of this DOTS Tutorial?
  • Important Notes For Using This Gitbook
  • Unity ECS
    • Intro to Unity ECS
    • Create a Unity ECS Project
    • Spawn and Move Prefabs
    • Spawn and Move Players
    • Spawn Bullets and Destroy Player
    • Publish Builds in Unity ECS
  • Unity DOTS Physics
    • Intro to Unity DOTS Physics
    • Use DOTS Physics for Prefabs, Players, and Bullets
    • Use DOTS Physics for Collisions
  • Unity DOTS NetCode
    • Intro to DOTS NetCode
    • Create a Network Connection using DOTS NetCode
    • Load a Game using DOTS NetCode
    • DOTS NetCode and Prefabs
    • DOTS NetCode and Player Prefabs
    • Use DOTS NetCode for Collisions and Destroying Bullet Prefabs
    • Dynamically Changing Ghosts Between Interpolated and Predicted
  • UI Builder and UI Toolkit
    • Intro to UI Toolkit
    • Create a ScreenManager
    • Style a View
    • Create a ListView
    • Responsive Game UI
    • Navigate Between Scenes Using ClientServerBootstrap
  • Multiplayer (NetCode+, UI Toolkit+)
    • Intro to Unity NetCode Multiplayer
    • Host or Join a Multiplayer Session on LAN
    • Broadcast a LAN Multiplayer Game
    • Keep Score and Update Game UI
    • Send Ghosts with NetCode Using Relevancy
  • AR Foundation
    • Intro to AR Foundation
    • Set Up AR Foundation and ARKit
    • Spawn a Player using AR Foundation
    • Update UI using AR Foundation
Powered by GitBook
On this page
  • What you'll develop in this DOTS Physics section
  • Functionalities included
  • Unity DOTS Physics
  • Unity Resources
  • Setting up for this gitbook section on DOTS Physics
  1. Unity DOTS Physics

Intro to Unity DOTS Physics

Full workflows and code on how to get started with Unity DOTS Physics

PreviousPublish Builds in Unity ECSNextUse DOTS Physics for Prefabs, Players, and Bullets

Last updated 2 years ago

What you'll develop in this DOTS Physics section

Github branch link:

Functionalities included

  • Unity DOTS Physics

    • Using FixedStepSimulationGroup for custom systems

  • Physics Body

    • Adjusting PhysicsVelocity programmatically

  • Physics Shape

    • Updating shape type to prefab

  • Physics Categories

    • Custom categories for collisions and interactions

  • Triggers on collisions

    • Changing stateless triggers to buffer of stateful triggers

  • Acting on triggers to change materials and destroy entities

Unity DOTS Physics

Unity Resources

🔑 Major Key Alert 🔑

A good way to approach implementing DOTS Physics is by checking out the DOTS Physics samples and finding an example similar to what you're looking to implement, and then copying, pasting, and modifying to your needs. This is the approach we will use in this section.

The current Physics documentation is difficult and trying to build these functionalities from scratch is a Sisyphean task. It's much simpler to grab code from Unity's samples since there's a lot of "boilerplate" for a majority of the Physics interactions.

Setting up for this gitbook section on DOTS Physics

    • Or you could use:

    git clone https://github.com/Unity-Technologies/EntityComponentSystemSamples.git

    • in terminal to download the repository

  • Open the downloaded repository navigate to PhysicsSamples > Assets > Demos > 2. Setup > 2d. Events > 2d1. Events - Triggers.unity

    • This will warn you that our Unity version (2020 LTS) is different than the sample version

    • This is okay and will not cause issues so click Continue

  • This is a good sample because it shows both triggers and collisions

    • Breaking the translucent red cubes triggers gravity to switch

    • The balls collide with each other

  • Navigate into the "2d1. Triggers" folder and open "2d1a. Triggers - Change Material"

  • We will base our Physics updates to our project on this sample

  • The balls change colors when passing through the colored prisms and collide with the block objects

  • Our bullets will pass through and change the material of asteroids and players (similar to how the balls pass through the prisms)

  • Bullets passing through an asteroid or player will also trigger adding a DestroyTag to those entities which will cause them to be destroyed

  • Select different prefab GameObjects in the Hierarchy (ex: "Floor" under Physics Scene Basic Elements), and notice the Physics Shape component in the Inspector

    • Under "Collision Filter" in the Material section (still in the Physics Shape component) check out the "Belongs To" and "Collides With" fields

      • If you can't find Collision Filter, expand the Physics Shape component section

    • Different GameObjects in the Hierarchy have different values set for "Belongs To" and "Collides With"

    • This is how we tell Unity Physics what entities interact with each other

  • Scroll to the bottom of the "Collides With" drop down list and select "Edit Physics Category Names" to be taken to PhysicsCategoryNames in the main Assets folder

  • Take a look at the different categories for all the samples in the repo

  • We can see that in DOTS Physics, the Physics Shape component on our prefabs will decide what the prefab interacts with

  • Also in the Physics Shape component under "Material" there is a field called "Collision Response" with 4 options:

    • Collide (bang together, which our players and asteroids will do)

    • Collide and Raise Collision Events (bang together and cause an event; we will not be using this in this gitbook only because we do not want to over-complicate things by doing too much)

    • Raise Trigger Events (not bang together but cause a trigger event, like our bullets will do to players and asteroids)

    • None (nothing happens from collisions)

To best prepare for the following DOTS Physics code-alongs, we recommend you complete the following check-list:

Unity's 2019 overview of physics in DOTS: Recommended to watch.

Unity's 2020 update of physics: If interested in the latest and greatest.

Link to Unity's DOTS Physics samples: Good place to see the contents of the Physics Samples without opening Unity Editor (ReadMe is missing some samples that are contained in the repo so a little misleading)

Unity's DOTS Physics v0.50.0-preview.43 documentation overview: . Key to get an understanding

Unity DOTS Physics forum: Helpful to find answers to questions.

Checkout how Code Monkey follows this technique in his "Getting Started with Unity DOTS Physics" video:

Go to and download the repository for Unity's ECS Samples (if you haven't already)

Join our Discord for more info
https://www.youtube.com/watch?v=tI9QfqQ9ATA
https://www.youtube.com/watch?v=n_5RGdF7Doo
https://github.com/Unity-Technologies/EntityComponentSystemSamples/blob/master/UnityPhysicsSamples/Documentation/samples.md
https://docs.unity3d.com/Packages/com.unity.physics@0.50/manual/getting_started.html
https://forum.unity.com/forums/dots-physics.422/
https://www.youtube.com/watch?v=B3SFWm9gkL8
https://github.com/Unity-Technologies/EntityComponentSystemSamples
Join our Discord for more info
https://github.com/moetsi/Unity-DOTS-Multiplayer-XR-Sample/tree/Updating-Bullets-to-Destroy
Shooting red bullets to destroy asteroids, powered by DOTS Physics
Download Unity ECS Samples repo
Showing Unity Physics sample
Navigating to Change Material scene
Navigating through GameObjects in the scene Hierarchy and taking a look at Collision Filter fields