Unity NetCode 0.0.2-preview.1

The first preview version of the Unity NetCode package has been released and is now available in the Unity package manager.

Package documentation
Samples (See Asteroids and NetCube)
Unite presentation about NetCode

What is it?
The Unity NetCode package is our implementation of a server authoritative multiplayer model with client prediction for DOTS. It is the package we are using in the DotsSample from Unite Copenhagen. In this model all simulation is happening on the server and the NetCode is synchronizing networked objects - ghosts - to all clients. The clients send inputs to the server and it is also possible to send light-weight RPCs for control flow.

We have been running playtests with 30-40 players from around the world with it regularly, and also a few playtests with more players. With the compression we have in place the bandwidth is usually well below 100kbit/s on the client in our playtests.

What is it not?
This is the first preview of the new NetCode package. As such it is not a full featured solution, the main focus has been on getting the core of it solid rather than making it feature complete or easy to use. There is also not a lot of documentation available yet.

This is not the only networking model we plan to build, but it is the one we are building first. Other networking models will follow once this one is more mature.

17 Likes

As my usecase for Unity is rather abnormal, I’d assume this doesn’t have a DOTS solution to connecting to an existing TCP secure websocket correct? First glance of the documentation would indicate it has nothing related to that, but thought I might ask on the off chance there was something already built within the package :slight_smile:

Yay! Thank you very much! Time to update!

We do not have any TCP socket support right now so websockets will not work. Should be fine to use regular C# sockets as long as you do it from the main thread though. We are actually doing something like that for our NetDbg tool in the NetCode.

1 Like

I do not seem to be able to find the package in the package manager (even though I have preview-packages enabled).
Nor am I able to find any release / pre-release of Unity 2019.3 in Unity Hub, is this an issue anyone else is experiencing?

Tim, can you give me a summary of the bigger changes that happened with 0.0.2?
If you can’t, no biggie, just interested.

There’s no code for lag compensation, is there?

Most of the changes are listed in the changelog ( https://docs.unity3d.com/Packages/com.unity.netcode@0.0/changelog/CHANGELOG.html )
If you want changes from the old github repo you need to look at both 0.0.2-preview.1 and 0.0.1-preview.6.
We did develop most of it in the DotsSample repo and were not very strict about updating the changelog so I’m pretty sure it is missing a lot of things - but the most important ones should be there.

2 Likes

The lag compensation is still part of the DotsSample code - but we will be moving it into packages (part of it will be in netcode, we do not have a final decision on if it will be all or if some part will live elsewhere due to physics dependencies). If you remind me I can point you at the code once it is released so you can get started before we move it in to the package, it is not a lot of code.

4 Likes

If I wouldn’t have forgotten, then I will surely remind you :p. Thanks for that though.

By the way, any ETAs on when the sample project will be released?

1 Like

I can’t find the package either, I’m on version 2019.3.0f1 though.

How about com.unity.transport package? Is that package is available via Package manager too? Also, Is it safe to use com.unity.transport alone without netcode package?

Yes, it is available as com.unity.transport 0.2.1-preview.1 and you can use it without using netcode.

1 Like

“com.unity.entities”: “0.2.0-preview.18”,
“com.unity.netcode”: “0.0.2-preview.1”,
“com.unity.rendering.hybrid”: “0.2.0-preview.18”,
“com.unity.test-framework”: “1.1.8”,
“com.unity.transport”: “0.2.1-preview.1”,

1 Like

I have the new netcode up and running and it was a much better process than the last time. I like most new changes. Less code-gen, no seperate prediction systems.

Sadly I still ran into an older problem I couldn’t quite figure out. There seems to be a 1:1 relation between a type of ghost and its snapshot to a (converted) model.
If I want to have several moving platforms with a generic mover ghost I don’t know how to make them have seperate meshes. There doesn’t seem to be a pipeline for this and I’m wondering if it’s better to wait because there is something up and coming that solves this or roll my own implementation.

1 Like

GameObjects with GhostAuthoringComponent are converted twice in each of my client worlds, so I have two Entities per GameObject per World.
Is there a way to stop that from happening? Do I have to uncheck all the boxes for Interpolated Client / Predicted Client manually?
Why would a component need to be interpolated and predicted at the same time?

Any plan to add support for hybrid ECS (i.e. Convert and Inject Game Object conversion mode) for GhostAuthoringComponent? At least expose Convert and Inject Game Object conversion mode selection option just like how Convert To Entity does. Currently I have project implement in hybrid ECS way and I not able to use this netcode package as it needs to be in pure ECS. I think until there is most of Unity features available in dots, it’s must have feature.

The easiest way to solve this is to have system on the client which changes or adds the mesh based on other data in the ghost.
So you would add a MeshTypeComponent or something like that which you create yourself to synchronize a mesh index. On the client you run a system which looks at the mesh index in the MeshTypeComponent and changes the mesh based on that.
You could also mark the MeshComponent as not present on client and only run the system once for entities which have a MeshTypeComponent but not a MeshComponent and add the MeshComponent with the correct mesh based on the type.

The ghost is convert to two entity prefabs, one for interpolated and one for predicted. These are just prefabs and not actual entities, they will not show up in entity queries. When you receive a new ghost it will be instantiated from one of these two prefabs based on which type of ghost it is. A single instance of a ghost is never interpolated and predicted at the same time, but one ghost type can have both interpolated and predicted ghost instances.

Convert and inject is not something we are currently planning to do. I am not ruling out that we might do something like that in the future - but not short term. Ghosts are converted to entity prefabs which are instantiated on the client side. That means the prefabs themselves cannot be hybrid.
It is just the synchronized data and prefab that needs to be pure ECS. You can still create hybrid games with it, but it requires some extra code. You would need to have a component on the ghost which a system on the client or server looks for and creates a GameObject or other hybrid data based on. So instead of creating a prefab with hybrid components on it you would create it with a NeedsHybridComponent and run a system which creates the required GameObjects / components for entities with that component.

1 Like