DOTS NetCode 0.3.0 released

A few minutes ago we published com.unity.netcode@0.3.0-preview.3 .

This release requires Unity 2020.1.2 and entities 0.14.

NetCode 0.3.0 is a significant change to the authoring workflows for ghosts. We now automatically generate code per component and no longer do any code generation per ghost prefab. Since it is a major change any project using earlier versions of NetCode will unfortunately have to change some code to upgrade, please see the change log for details.

We also released com.unity.transport@0.4.0-preview.3 and updated the samples at GitHub - Unity-Technologies/multiplayer: Unity multiplayer packages and samples

Change logs:
https://docs.unity3d.com/Packages/com.unity.netcode@0.3/changelog/CHANGELOG.html
https://docs.unity3d.com/Packages/com.unity.transport@0.4/changelog/CHANGELOG.html

16 Likes

I’m porting my existing code base to Netcode 0.3.0 right now.
Can someone explain the usage of the new Composite field inside the GhostFieldAttribute?

On a different note i found out that multiple entity fields on the same component lead to the variable ghostEnt being declared multiple times inside the components serializer.

1 Like

Is it possible that 2020.2 is behind 2020.1 in terms of DOTS support? I tried opening the sample in 2020.2 and I’m getting errors about job reflection data

1 Like

Our new serialization code supports serializing structs, so if you can have patterns like this

public struct SomeData
{
    public int A;
    public int B;
}
public struct SomeComponent : IComponentData
{
    [GhostField] SomeData Data;
}

Part of out delta compression is a change mask - 1 bit per field in the component - saying if that field has changed. If it has not changed the data is not part of the snapshot. We also delta compress those change masks to make non-changing fields zero bits (there are some side effects which make subsequent changes slightly more expensive in a few cases, but generally the cost is <1bit).

The Composite field is something you can put on the GhostField attribute for the struct (the field called Data in my example) to control if you have one change mask bit per field in the inner struct, or one change mask bit for the inner struct as a whole. In my example it’s either two bits, one for A and one for B in the non-compoiste case, or 1 bit for SomeData in the composite case.
Which is better depends on how your data is changing. If A and B usually change together it’s probably better to use composite, but if one changes frequently and one rarely it might be better to use non-composite.

Thanks, we’ll fix that. It would be great if you can file a bug for it in the Unity bug reporter so we get tracking on it

2 Likes

We are working on fixing that and will get a netcode version with Unity 20.2 support out as soon as we can

6 Likes

Will do!

1 Like

Just a random note, your Source Project for Workflows (https://oc.unity3d.com/index.php/s/PHaNZP79Va2YOLT.md)
on the Unity Transport documentation (About Unity.Networking.Transport | Unity Transport | 0.4.1-preview.1)

Throws up misconfigured errors as your certificate expired a month ago

Websites prove their identity via certificates, which are valid for a set time period. The certificate for oc.unity3d.com expired on 7/22/2020.
Error code: SEC_ERROR_EXPIRED_CERTIFICATE

1 Like

I really like the addition of [GhostComponent] and [GhostField]. They allow me to easily make a plug-n-play NetCode integration for my package instead of having to write a big guide on which variables in my package’s components have to be networked and how to setup ghosts

8 Likes

How can I add attribute to reserved IComponentData like Translation, Rotation and RenderMesh since it’s being used by official?

1 Like

In the doc’s “Getting Started”, it says whenever you add a GhostAuthoring component, it automatically adds replication fields for Translation and Rotation

But I’d also be curious to know how we can replicate other fields that weren’t maked with [GhostField], but are in packages that we don’t want to modify. I’m guessing that if NetCode can add those automatically, we might be able to do that as well

1 Like

@optimise @PhilSA you can use IGhostDefaultOverridesModifier to register components from ECS packages. This link briefly mentions how to set it up
https://docs.unity3d.com/Packages/com.unity.netcode@0.3/manual/ghost-snapshots.html

1 Like

@timjohansson Just a quick note: The markdown on the changelog page is not working – titles (eg. ### Fixes) are not correctly used and not transformed into their HTML counterparts (Change log | Unity NetCode | 0.3.0-preview.3).

1 Like

I am wondering what GhostGroups are exactly and how I could maybe use them.

GhostGroups are now supported. A ghost prefab can have a GhostGroup buffer added to it at authoring time, all ghosts listed in that buffer are guaranteed to be sent together with the main entity. In order to be in a group the child ghost must have the GhostChildEntityComponent component added to it. The GhostChildEntityComponent can be added at runtime when moving the child entity into the group.

I’m guessing it’s for adding virtual children to another ghost prefab… am I off the mark?

Another question – how can syncing of Translation or Rotation of children be enabled, for example for a rotating turret?


In the picture: Rotation is synced for the root, but not for child 0 (no fields are listed, and it is not rotating in the client, but it is on the server).

Is anyone else getting “Internal: deleting an allocation that is older than its permitted lifetime of 4 frames” warnings in the Asteroids sample?
I’m on 2020.1.3f1

1 Like

do you have vsync on

because netcode runs at a fixed framerate, you need to limit your fps so it’s not 4x higher than the update rate
(they are looking into a way to fix this)

Vsync is turned on. I’m still getting more than 60+ fps shown in game stats. Isn’t simulation tick rate now independent of rendering framerate?

Tempjob allocation is still tied to frame rate - this is what needs fixing.

https://discussions.unity.com/t/776940/6

You are mostly correct, but it is important to note that the group itself is not replicated at the moment, so you can’t get the list of group members on the client side - you have to add entity references to them. The main use-case it intends to solve is if you have a player and a replaceable weapon or ability owned by the player (which is not known at authoring time) and you want to make sure those two ghosts are always sent together so you know they are in sync.

2 Likes

You have to use the same IGhostDefaultOverridesModifier as when adding new default overrides mentioned in https://docs.unity3d.com/Packages/com.unity.netcode@0.3/manual/ghost-snapshots.html (create a class implementing that interface in an assembly with a name ending with “.NetCodeGen”)

Instead of adding a new item you modify an existing one, so in the Modify method you would do something like

overrides["Unity.Transforms.Translation"].attribute.SendDataForChildEntity = true;
overrides["Unity.Transforms.Rotation"].attribute.SendDataForChildEntity = true;

Doing that will mean all translation and rotation components are ghosted for child entities in ghosts.

This is not the finalized API for it and I expect the way you do this to change in the future.

Edit: should also mention that the code is kind of pseudo-code, I did not compile and run it so you might need to change it slightly

2 Likes