Skip to content

Commit 8f73bb5

Browse files
author
Unity Technologies
committed
com.unity.netcode@0.2.0-preview.5
## [0.2.0-preview.5] - 2020-06-05 ### New features * Support for pre-spawned ghosts. When prefab ghost instances are placed into subscenes they will be present on server and clients when they load the scene. They are then automatically connected together and will work just like normally spawned ghosts after that. ### Changes * Changed how snapshot size is limited to make it more robust and give more clear errors. * Added `Name` field to the `GhostAuthoringComponent` which is used during code generation to identify the ghost prefab. By default this is the prefab name but can be changed. * `ClientServerBoostrap` now correctly use two-phase initialization to initialise all the systems * Changed `PhysicsWorldHistory.CollisionHistoryBuffer` to return a safe memory reference to the `CollisionHistoryBuffer` instead of copy a large amount of data on the stack. * Upgrade to Entities 0.11 ### Fixes * Fixed issue with ghost prefabs when they were Variant or Model Prefabs. * Fixed issue with datastream going out of sync when snapshot desync was detected * Fixed an issue with `RegisterRPC` in case you try to register a malformed RPC with an invalid pointer * Fixed an issue with `ServerTick` that does not monotonically increase in presence of high ping * Fixed an issue with `ClientServerTickRate` being created multiple times if the client connect and disconnect from the server * Fixed an issue with `ClientServerTickRate` not reused by the client if it was already present in the world * Fixed an issue with `ClientServerBootstrap` and the fact `TypeManager` was not initialised when we generate client/server world's the system lists ### Upgrade guide * A `Name` field was added to the `GhostAuthoringComponent` and as a result all prefabs with this component need to be opened and close to serialize the field. It's used as a prefix name during code generation so it might also be neccessary to press the _Generate Code_ button again
1 parent d9406ff commit 8f73bb5

File tree

56 files changed

+2083
-587
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+2083
-587
lines changed

CHANGELOG.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,29 @@
11
# Change log
22

3+
## [0.2.0-preview.5] - 2020-06-05
4+
### New features
5+
* Support for pre-spawned ghosts. When prefab ghost instances are placed into subscenes they will be present on server and clients when they load the scene. They are then automatically connected together and will work just like normally spawned ghosts after that.
6+
7+
### Changes
8+
* Changed how snapshot size is limited to make it more robust and give more clear errors.
9+
* Added `Name` field to the `GhostAuthoringComponent` which is used during code generation to identify the ghost prefab. By default this is the prefab name but can be changed.
10+
* `ClientServerBoostrap` now correctly use two-phase initialization to initialise all the systems
11+
* Changed `PhysicsWorldHistory.CollisionHistoryBuffer` to return a safe memory reference to the `CollisionHistoryBuffer` instead of copy a large amount of data on the stack.
12+
* Upgrade to Entities 0.11
13+
14+
### Fixes
15+
* Fixed issue with ghost prefabs when they were Variant or Model Prefabs.
16+
* Fixed issue with datastream going out of sync when snapshot desync was detected
17+
* Fixed an issue with `RegisterRPC` in case you try to register a malformed RPC with an invalid pointer
18+
* Fixed an issue with `ServerTick` that does not monotonically increase in presence of high ping
19+
* Fixed an issue with `ClientServerTickRate` being created multiple times if the client connect and disconnect from the server
20+
* Fixed an issue with `ClientServerTickRate` not reused by the client if it was already present in the world
21+
* Fixed an issue with `ClientServerBootstrap` and the fact `TypeManager` was not initialised when we generate client/server world's the system lists
22+
23+
### Upgrade guide
24+
25+
* A `Name` field was added to the `GhostAuthoringComponent` and as a result all prefabs with this component need to be opened and close to serialize the field. It's used as a prefix name during code generation so it might also be neccessary to press the _Generate Code_ button again
26+
327
## [0.1.0-preview.6] - 2020-02-24
428
### New features
529
* Added integration with UnityPhysics, including the lag compensation from DotsSample. To use it you must have the UnityPhysics added to your project.

Documentation~/getting-started.md

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,16 @@ public struct MovableCubeComponent : IComponentData
4242

4343
Once you create this component, add it to the Cube Prefab. Then, in the Inspector, add the __Ghost Authoring Component__ to the Prefab. In this component, select __Update Component List__ to update the list of components.
4444

45-
When you do this, Unity automatically adds default values to the Translation and Rotation components. Expand the components in the list to select where they should be present. In this example, disable `PerInstanceCullingTag` and `RenderMesh` on the server. This is because the server does not render anything, and interpolated objects on the client don’t simulate anything.
4645

47-
![The Ghost Authoring component](images/ghost-config.png)<br/>_The Ghost Authoring component_
4846

49-
**Note:** Change the __Default Client Instantiation__ to __Owner Predicted__. This makes sure that you predict your own movement.
47+
When you do this, Unity automatically adds default values to the Translation and Rotation components.
48+
49+
Start by changing the __Default Client Instantiation__ to __Owner Predicted__. This makes sure that you predict your own movement. Then, add the `MovableCubeComponent.PlayerId` to the
50+
__Predicting player network id__ field.
51+
52+
Now, expand the components in the list to select where they should be present. In this example, disable `PerInstanceCullingTag`, `RenderBounds` and `RenderMesh` on the server. The server doesn't render anything and interpolated objects on the client don't simulate anything, so these settings aren't required.
53+
54+
![The Ghost Authoring component](images/ghost-config.png)<br/>_The Ghost Authoring component_
5055

5156
After you set up the component, select the __Generate Code__ button.
5257

@@ -118,11 +123,11 @@ In *Game.cs*, create the following [RpcCommand](https://docs.unity3d.com/Package
118123
[BurstCompile]
119124
public struct GoInGameRequest : IRpcCommand
120125
{
121-
public void Deserialize(DataStreamReader reader, ref DataStreamReader.Context ctx)
126+
public void Deserialize(ref DataStreamReader reader)
122127
{
123128
}
124129

125-
public void Serialize(DataStreamWriter writer)
130+
public void Serialize(ref DataStreamWriter writer)
126131
{
127132
}
128133
[BurstCompile]
@@ -161,28 +166,28 @@ public struct CubeInput : ICommandData<CubeInput>
161166
public int horizontal;
162167
public int vertical;
163168

164-
public void Deserialize(uint tick, DataStreamReader reader, ref DataStreamReader.Context ctx)
169+
public void Deserialize(uint tick, ref DataStreamReader reader)
165170
{
166171
this.tick = tick;
167-
horizontal = reader.ReadInt(ref ctx);
168-
vertical = reader.ReadInt(ref ctx);
172+
horizontal = reader.ReadInt();
173+
vertical = reader.ReadInt();
169174
}
170175

171-
public void Serialize(DataStreamWriter writer)
176+
public void Serialize(ref DataStreamWriter writer)
172177
{
173-
writer.Write(horizontal);
174-
writer.Write(vertical);
178+
writer.WriteInt(horizontal);
179+
writer.WriteInt(vertical);
175180
}
176181

177-
public void Deserialize(uint tick, DataStreamReader reader, ref DataStreamReader.Context ctx, CubeInput baseline,
182+
public void Deserialize(uint tick, ref DataStreamReader reader, CubeInput baseline,
178183
NetworkCompressionModel compressionModel)
179184
{
180-
Deserialize(tick, reader, ref ctx);
185+
Deserialize(tick, ref reader);
181186
}
182187

183-
public void Serialize(DataStreamWriter writer, CubeInput baseline, NetworkCompressionModel compressionModel)
188+
public void Serialize(ref DataStreamWriter writer, CubeInput baseline, NetworkCompressionModel compressionModel)
184189
{
185-
Serialize(writer);
190+
Serialize(ref writer);
186191
}
187192
}
188193
```

Documentation~/ghost-snapshots.md

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,46 @@ You need to implement some specific code to handle the predicted spawning for pl
7474

7575
NetCode spawns entities on the client with a Prefab stored in the `GhostPrefabCollectionComponent` singleton. A `GhostCollectionAuthoringComponent` and a `ConvertToClientServerEntity` component that uses Client as the conversion target creates the Prefab.
7676

77+
## Prespawned ghosts
78+
79+
A ghost instance (an instance of a ghost prefab) can be placed in a subscene in the Unity editor so that it will be treated just like a normal spawned ghost when the player has loaded the data. There are two restrictions for prespwaned ghosts. Firstly, it must be an instance of a ghost prefab which has been registered in the ghost collection. Secondly, it must be place in a subscene.
80+
81+
The ghost authoring component on the prespawned ghost cannot be configured differently than the ghost prefab source, since that data is handled on a ghost type basis.
82+
83+
Each subscene applies prespawn IDs to the ghosts it contains in a deterministic manner. The subscene hashes the component data on the ghosts, which currently is only the `Rotation` and `Translation` components. It also keeps a single hash composed of all the ghost data for the subscene itself.
84+
85+
At runtime, when all subscenes have been loaded, there is a process which applies the prespawn ghost IDs to the ghosts as normal runtime ghost IDs. This has to be done after all subscenes have finished loading and the game is ready to start. It is also done deterministically, so that for each player (server or client), the ghost IDs are applied in exactly the same way. This happens when the `NetworkStreamInGame` component has been added to the network connection. Currently, there is no reliable builtin way to detect when subscenes have been loaded. However, it's possible to do so manually. To do this, add a custom tag to every subscene, then count the number of tags to detect when all subscenes are ready.
86+
87+
An alternative way to detect whether subscenes have finished loading without using tags is to check if the prespawn ghost count is correct. The following example shows one possible solution for checking this number, in this case testing for 7 ghosts across all loaded subscenes:
88+
89+
```c#
90+
[UpdateInGroup(typeof(ClientSimulationSystemGroup))]
91+
public class GoInGameClientSystem : ComponentSystem
92+
{
93+
public int ExpectedGhostCount = 7;
94+
protected override void OnUpdate()
95+
{
96+
var prespawnCount = EntityManager.CreateEntityQuery(ComponentType.ReadOnly<PreSpawnedGhostId>()).CalculateEntityCount();
97+
Entities.WithNone<NetworkStreamInGame>().ForEach((Entity ent, ref NetworkIdComponent id) =>
98+
{
99+
if (ExpectedGhostCount == prespawnCount)
100+
PostUpdateCommands.AddComponent<NetworkStreamInGame>(ent);
101+
});
102+
}
103+
}
104+
```
105+
106+
To create a prespawned ghost from a normal scene you can do the following:
107+
* Right click on the *Hierarchy* in the inspector and click *New Sub Scene*.
108+
* Drag an instance of a ghost prefab into the newly created subscene.
109+
110+
This feature is new and is liable to change in the future. The current implementation has some limitations which are listed below:
111+
* With regard to using subscenes, when placing an object in a subscene, you no longer place the `ConvertToClientServerEntity` component on it as being in a subscene implies conversion to an Entity. Also, it means the option of making an entity only appear on the client or server is now missing. Prespawned ghosts always appear on both client and server as they are just like a normal spawned ghost, and will always be synchronized (as configured) after the game starts.
112+
* Loading a new subscene with prespawned ghosts after starting (entering the game) is currently not supported.
113+
* Only the `Translation` and `Rotation` `IComponentData` components, converted from the `Transform` component, are currently used to generate the prespawn IDs. This means that the prespawn ghosts cannot be placed in the same location and these components are required to use prespawn ghosts.
114+
115+
To look at an example of a scene using prespawn ghosts, see the test in *Assets/Tests/PrespawnTests*. This is used in some of the tests inside the sample project.
116+
77117
## Snapshot visualization tool
78118

79-
To understand what is being put on the wire in the netcode, you can use the prototype snapshot visualization tool, __NetDbg__ in the Stats folder. To open the tool, go to menu: __Multiplayer &gt; Open NetDbg__, and the tool opens in a browser window. It displays a vertical bar for each snapshot Unity receives, with a breakdown of the snapshot’s ghost types. To see more detailed information about the snapshot, click on one of the bars. __Note:__ This tool is a prototype. In future versions of the package it will integrate with the Unity Profiler so you can easily correlate network traffic with memory usage and CPU performance.
119+
To understand what is being put on the wire in the netcode, you can use the prototype snapshot visualization tool, __NetDbg__ in the Stats folder. To open the tool, go to menu: __Multiplayer &gt; Open NetDbg__, and the tool opens in a browser window. It displays a vertical bar for each snapshot Unity receives, with a breakdown of the snapshot’s ghost types. To see more detailed information about the snapshot, click on one of the bars. __Note:__ This tool is a prototype. In future versions of the package it will integrate with the Unity Profiler so you can easily correlate network traffic with memory usage and CPU performance.
1.29 KB
Loading

0 commit comments

Comments
 (0)