How to implement NetCode to Unity physics (new one, with Havok)

Hello, there are two technologies.

  1. Unity physics for ECS (https://github.com/Unity-Technologies/EntityComponentSystemSamples/tree/master/UnityPhysicsSamples)
  2. NetCode for ECS (GitHub - Unity-Technologies/multiplayer: Unity multiplayer packages and samples)
    I looked over all the internet but didn’t find any demo or project which uses both of them.
    So the questions.
    Is it available to use NetCode network synchronization on new Unity physics?
    And is there any project to look at how it can be implemented in each one?

Take a look at this tutorial.

It’s updated to the latest DOTS version as of October 2021.

1 Like

I’ve checked it. No, it’s not updated. The problem is much deeper and complicated. It supports only the 2020.1 Unity version.

From the author @adammpolak :

We are changing the recommended Unity version back to 2020.1.17f1 in the gitbook

Why: There is still a remaining error to move to 2020 LTS: https://discussions.unity.com/t/852686/12

Brief history:

I believe incorporating these issues into the gitbook would detract from learning about the basics of DOTS and how to incorporate it into monobehaviors, UI Toolkit, NetCode, ARFoundation

Rather than piece-mealing these updates with hacks, we are thinking that we will leave the gitbook referring to 2020.1.17f1 packages, and instead append a new section at the end that is something along the lines of “fixes to make these packages work on 2020LTS” (cc @dyhmichail )


The tutorial works perfectly fine with the current 2020.3 DOTS version. They just dont want to manually patch the various broken packages (DOTS is in alpha, there are bugs) so everything works perfectly.

You can do it yourself, the links are right there.

1 Like

If using entities you ought to remain on 2020, and not use 2021.x tech stream.

Yea, we’re talking about how the tutorial still recommends 2020.1 instead of the current 2020.3 due to bugs still remaining in the various DOTS and other packages.

For example, DOTS + UIToolkit + Input System breaks due to changes in assembly definitions and their problems in 2020.3 while it still works in 2020.1.

1 Like

I’m assuming you’re talking about implementing prediction for physics, so that player-controlled/player-affected rigidbodies can be responsive & networked. I haven’t tested in practice, but I think it would be something like this:

  • Make sure all rigidbodies are network ghosts
  • Make sure all PhysicsVelocity.Linear/Angular are ghost fields
  • Make sure physics Build/Step/Export/End systems are all part of the GhostPredictionGroup update

If you don’t need prediction, you could simply do:

  • have the physics simulation run only on server (don’t run physics systems on clients)
  • only synchronize the translation/rotation of rigidbodies (as ghosts)
  • when you need to apply any kind of force/change to a rigidbody, you just send an RPC to the server for applying that change (you will see the change on your client, but with a slight delay)

In theory, you are right, but the problem is much simpler. When you install all the newest packs (DOTS, ECS, NetCode, UI Builder etc.) on the last Unity version they begin to conflict with each other. There are a lot of threads about it.

https://forum.unity.com/threads/2020-3-16f1-physics-world-history-objectdisposedexception-cannot-access-a-disposed-object.1158956
https://forum.unity.com/threads/unity-collections-1-0-0-pre-3.1138633
https://forum.unity.com/threads/subscenes-ui-entity-header-failed-to-load.1007609
https://forum.unity.com/threads/ui-toolkit-1-0-0-preview-14-unity-2021-1-16f1-bug.1150016
and so on.