Skip to content

Commit 0f13adf

Browse files
authored
Merge branch 'develop-3.x.x' into fix/test-canonical-random-bools
2 parents ba2ae2f + 16a7308 commit 0f13adf

11 files changed

Lines changed: 282 additions & 41 deletions

File tree

‎.yamato/ngo-publish.yml‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
ngo_release_preparation:
22
name: "NGO release preparation"
33
agent: { type: Unity::VM, flavor: b1.small, image: package-ci/ubuntu-22.04:v4 }
4-
triggers:
5-
recurring:
6-
- branch: develop-3.x.x # We make new releases from this branch
7-
frequency: "10 ? * 1" # Runs every Sunday at 10:00 AM
84
commands:
95
- pip install PyGithub
106
- pip install GitPython

‎com.unity.netcode.gameobjects/CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ Additional documentation and release notes are available at [Multiplayer Documen
2323

2424
### Fixed
2525

26+
- Issue where a client promoted to session owner could throw an exception when synchronizing a newly joining client. (#4214)
2627
- Issue where a client's clock kept alternating between running slightly fast and slightly slow on every frame, even after it had synchronized with the server. Interpolated objects juddered (a periodic motion artifact caused by mismatched frame rates): they moved in uneven steps instead of smoothly. Barely noticeable at the default `NetworkTimeSystem.AdjustmentRatio`, and clearly visible at higher values.
2728
- Issue where the IL post-processor could not resolve core library types, such as `Guid` and `List<T>`, in assemblies compiled against .NET reference assemblies, for example when targeting .NET 10. Those split the core library across `System.Runtime`, `System.Collections` and other assemblies.
2829
- Fixed issue where a prefab added to a `NetworkPrefabsList` while a session was running was registered more than once and logged a duplicate `GlobalObjectIdHash` error. (#4184)

‎com.unity.netcode.gameobjects/Documentation~/TableOfContents.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,15 @@
3232
* [NetworkBehaviour ownership](components/core/networkbehaviour-ownership.md)
3333
* [NetworkManager](components/core/networkmanager.md)
3434
* [PlayerObjects and player prefabs](components/core/playerobjects.md)
35-
* [Helper Components](components/helper/helpercomponents.md)
35+
* [Helper components](components/helper/helpercomponents.md)
3636
* [AttachableBehaviour](components/helper/attachablebehaviour.md)
3737
* [AttachableNode](components/helper/attachablenode.md)
3838
* [ComponentController](components/helper/componentcontroller.md)
3939
* [NetworkAnimator](components/helper/networkanimator.md)
4040
* [NetworkRigidbody](components/helper/networkrigidbody.md)
4141
* [NetworkTransform](components/helper/networktransform.md)
4242
* [Physics](advanced-topics/physics.md)
43+
* [Hybrid objects (GhostObjects)](ghostobjects.md)
4344
* [Spawning and despawning](spawn-despawn.md)
4445
* [Object spawning](basics/object-spawning.md)
4546
* [Network prefab handler](advanced-topics/network-prefab-handler.md)

‎com.unity.netcode.gameobjects/Documentation~/components/helper/networktransform.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ When __Tick Sync Children__ is enabled, the top-most parent NetworkTransform aut
145145
146146
#### Network conditions to consider
147147

148-
Sometimes network conditions are poor, with packets experiencing latency and potentially packet loss. When NetworkTransform [interpolation](#interpolation) is enabled, packet loss can mean undesirable visual artifacts such as stutter. To try and mitigate these issues, NetworkTransform defaults to sending delta state updates (such as position, rotation, or scale changes) as unreliable sequenced network-delivered messages. This ensures that if one state is lost then the `BufferedLinearInterpolator` can recover easily, because it doesn't have to wait precisely for the next state update and can just lose a small portion of the overall interpolated path. For example, with a `TickRate` setting of 30, you could lose 5 to 10% of the overall state updates over one second and still have a relatively similar interpolated path to that of a perfectly delivered 30 delta state updates generated path. The [__UseUnreliableDeltas__](#unreliable-state-updates) NetworkTransform property, which defaults to disabled, controls whether you send your delta state updates unreliably or reliably.
148+
Sometimes network conditions are poor, with packets experiencing latency and potentially packet loss. When NetworkTransform [interpolation](#interpolation) is enabled, packet loss can mean undesirable visual artifacts such as stutter. By default, NetworkTransform sends delta state updates (such as position, rotation, or scale changes) as reliable messages. To mitigate these issues, you can enable the [__UseUnreliableDeltas__](#unreliable-state-updates) NetworkTransform property to send delta state updates as unreliable sequenced messages instead. Sending delta state updates unreliably ensures that if one state is lost then the `BufferedLinearInterpolator` can recover easily, because it doesn't have to wait precisely for the next state update and can just lose a small portion of the overall interpolated path. For example, with a `TickRate` setting of 30, you could lose 5 to 10% of the overall state updates over one second and still have a relatively similar interpolated path to that of a perfectly delivered 30 delta state updates generated path.
149149

150150
Of course, you might wonder what would happen if 5% of the end of a jumping motion were dropped and how NetworkTransform might recover since each state update sent is only based on axial deltas defined by each axis threshold setting. The answer is that there is a small bandwidth penalty for sending standard delta state updates unreliably, full axial frame synchronization, which assures that in the event there is loss each NetworkTransform will be "auto-corrected" once per second.
151151

@@ -157,7 +157,7 @@ Of course, you might wonder what would happen if 5% of the end of a jumping moti
157157
When unreliable state updates are enabled, NetworkTransform instances are assigned a constantly rolling tick position relative to a one-second period of time. If you're using the default `NetworkConfig.TickRate` value (30), then there are 30 "tick slots" that each NetworkTransform instance is distributed amongst on the authoritative instance. This means that each instance sends one axial frame synchronization update per second while the NetworkObject in question is moving, rotating, or scaling enough to trigger delta state updates. When a NetworkObject comes to rest (and is no longer sending delta state updates) the axial frame synchronization stops. This ensures that if a vital portion of a state update is dropped, within a one-second period of time, all axes marked to be synchronized will be synchronized to provide an eventual consistency in axis synchronization between the authority and non-authority instances.
158158

159159
> [!NOTE]
160-
> If bandwidth consumption becomes a concern and you have tested your project under normal network conditions with `UseUnreliableDeltas` disabled with no noticeable visual artifacts, then you can opt out of unreliable delta state updates to recover the minor penalty for being packet loss tolerant. Or you can opt to make that an in-game configuration setting that players can enable or disable. You just need to update the authoritative NetworkTransform instances with any change in the setting during runtime.
160+
> Unreliable delta state updates use slightly more bandwidth than reliable updates, because of the additional axial frame synchronization. If bandwidth consumption is a concern and you have tested your project under normal network conditions with `UseUnreliableDeltas` disabled with no noticeable visual artifacts, then keep `UseUnreliableDeltas` disabled. Alternatively, you can make `UseUnreliableDeltas` an in-game configuration setting that players can enable or disable. You just need to update the authoritative NetworkTransform instances with any change in the setting during runtime.
161161
162162
### Configurations
163163

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# Hybrid objects (GhostObjects)
2+
3+
Understand how to use GhostObjects from Unity Netcode to support client-side prediction.
4+
5+
GhostObjects are a feature of [Unity Netcode](https://docs.unity3d.com/Packages/com.unity.netcode@latest) that let you build networked gameplay with GameObjects and MonoBehaviours, while Unity Netcode handles replication, prediction, and interpolation for you. By adding a GhostObject component to the root of a GameObject prefab, you can use Unity Netcode to synchronize the transform of the GameObject and its children, and optionally synchronize the state of its Rigidbody component. You can also use GhostObjects to implement client-side prediction for your networked gameplay.
6+
7+
A hybrid object is a GameObject that has both a [NetworkObject](components/core/networkobject.md) component and a [GhostObject](https://docs.unity3d.com/Packages/com.unity.netcode@latest?subfolder=/manual/ghostobject/ghostobject.html) component. Unity Netcode synchronizes the transform of a hybrid object as part of its snapshot, which makes the object compatible with prediction in Unity Netcode. Netcode for GameObjects continues to synchronize the data in your [`NetworkBehaviour`](xref:Unity.Netcode.NetworkBehaviour)s, such as [`NetworkVariable`](networkvariables-landing.md)s and RPCs.
8+
9+
When the network prefabs list contains a hybrid object, Netcode for GameObjects uses Unity Netcode to drive the connection, and Unity Netcode drives the physics system. The **Parent Replication** setting on the GhostObject component controls how you set the parent GameObject of a hybrid object. Hybrid objects have some [limitations](#hybrid-object-limitations), including incompatibility with the distributed authority topology, in-scene placed objects, and object pooling.
10+
11+
To create a hybrid object, add a GhostObject component to a NetworkObject prefab, or a NetworkObject component to a GhostObject prefab.
12+
13+
## How hybrid objects synchronize data
14+
15+
A hybrid object synchronizes its data through two separate systems:
16+
17+
- Unity Netcode synchronizes the transform of the hybrid object in its snapshot. If you enable **Replicate Rigidbody** on the **GhostObject** component, Unity Netcode also synchronizes the state of the Rigidbody component. Unity enables this option by default.
18+
- Netcode for GameObjects synchronizes the data in the hybrid object's `NetworkBehaviour`s, including `NetworkVariable`s, RPCs, and spawn data. Netcode for GameObjects sends this data separately from the Unity Netcode snapshot.
19+
20+
Because Netcode for GameObjects data isn't part of the snapshot, Unity Netcode doesn't roll back or replay `NetworkVariable`s, RPCs, or spawn data as part of its prediction loop. To use prediction on a hybrid object, write your prediction code in `GhostBehaviour`s. Prediction code in `GhostBehaviour`s on hybrid objects works the same way as on any other GhostObject.
21+
22+
When you convert a NetworkObject into a hybrid object, Netcode for GameObjects sets the GhostObject's supported ghost modes to interpolated only. To use prediction, change the `SupportedGhostModes` and `DefaultGhostMode` settings on the **GhostObject** component to include a predicted mode. For more information about ghost modes, refer to the [Unity Netcode documentation](https://docs.unity3d.com/Packages/com.unity.netcode@latest).
23+
24+
### Effect on existing transform and physics components
25+
26+
When you convert a NetworkObject into a hybrid object, any existing [NetworkTransform](components/helper/networktransform.md) and [NetworkRigidbody](components/helper/networkrigidbody.md) components stay on the prefab so that you don't lose their settings. However, they no longer synchronize data:
27+
28+
- A NetworkTransform component on a hybrid object has no effect, because Unity Netcode always synchronizes the transform.
29+
- A NetworkRigidbody component on a hybrid object has no effect when you enable **Replicate Rigidbody** on the **GhostObject** component.
30+
31+
If you convert the hybrid object back into a NetworkObject, these components resume synchronizing data with their existing settings.
32+
33+
## How Netcode for GameObjects uses Unity Netcode
34+
35+
When the network prefabs list on the [NetworkManager](components/core/networkmanager.md) contains a hybrid object, Netcode for GameObjects configures Unity Netcode and uses it to drive the connection. This changes how Netcode for GameObjects handles snapshot size and physics.
36+
37+
### Hybrid object requirements
38+
39+
Hybrid objects have the following requirements:
40+
41+
- A global `NetcodeConfig` asset. Unity Netcode creates this asset by default. If for some reason no global `NetcodeConfig` asset exists, the session fails to start and Netcode for GameObjects logs an error.
42+
- The `HostWorldModeSelection` setting of the global `NetcodeConfig` asset set to `SingleWorld`. If you use any other host world mode, the session fails to start and Netcode for GameObjects logs an error.
43+
44+
### Snapshot size
45+
46+
By default, Netcode for GameObjects configures the Unity Netcode snapshot size for you. To configure the snapshot size yourself in the `NetcodeConfig` asset, disable **Auto Configure Snapshot Size** in the **Hybrid Settings** section of the **NetworkManager** component.
47+
48+
### Physics simulation rate
49+
50+
When the network prefabs list contains a hybrid object, Unity Netcode drives the physics system. The physics system runs at the rate set in **Tick Rate** in the **Network Settings** section of the **NetworkManager** component. Unity Netcode uses this value instead of the **Simulation Tick Rate** value in the `ClientServerTickRate` settings of the `NetcodeConfig` asset.
51+
52+
For more information about tick rates in Netcode for GameObjects, refer to [Ticks and update rates](learn/ticks-and-update-rates.md).
53+
54+
## Parent replication
55+
56+
The **Parent Replication** setting on the **GhostObject** component controls which package synchronizes the parent GameObject of a hybrid object.
57+
58+
Unity disables **Parent Replication** by default. When you disable it, Netcode for GameObjects synchronizes parenting through its [NetworkObject parenting](advanced-topics/networkobject-parenting.md) methods, with the following behavior:
59+
60+
- Setting a parent with `worldPositionStays` set to `false` works as expected.
61+
- Setting a parent with `worldPositionStays` set to `true` has no effect, and Netcode for GameObjects logs an error.
62+
63+
When you enable **Parent Replication**, Unity Netcode synchronizes parenting, and you set the parent GameObject of a hybrid object in the same way as for any other GameObject. The NetworkObject parenting methods, such as [`NetworkObject.TrySetParent`](xref:Unity.Netcode.NetworkObject.TrySetParent*), have no effect, and Netcode for GameObjects logs an error if you call them.
64+
65+
## Hybrid object limitations
66+
67+
Hybrid objects have the following limitations:
68+
69+
- Distributed authority: Hybrid objects aren't compatible with the [distributed authority](terms-concepts/distributed-authority.md) topology. If the network prefabs list contains a hybrid object, a distributed authority session fails to start.
70+
- In-scene placed objects: [In-scene placed NetworkObjects](basics/scenemanagement/inscene-placed-networkobjects.md) can't be hybrid objects.
71+
- Object pooling: Hybrid objects aren't compatible with `INetworkPrefabInstanceHandler`, so you can't use [object pooling](advanced-topics/object-pooling.md) with hybrid objects.
72+
- Client authority: Unity Netcode doesn't support the client authoritative motion model. You can convert a NetworkObject that uses an owner-authoritative NetworkTransform into a hybrid object, but the owner no longer controls its transform, because the NetworkTransform component stops synchronizing data. To move the converted object, use server-authoritative motion or prediction instead. `NetworkVariable`s on hybrid objects can still use owner write permissions.
73+
74+
## Create and remove hybrid objects
75+
76+
To create a hybrid object, add the missing component to an existing network prefab:
77+
78+
- To convert a NetworkObject prefab into a hybrid object, select **Add Component** in the prefab's **Inspector** window and add a **GhostObject** component.
79+
- To convert a GhostObject prefab into a hybrid object, select **Add Component** in the prefab's **Inspector** window and add a **NetworkObject** component.
80+
81+
To convert a hybrid object back into a prefab that uses only one package, remove one of its components:
82+
83+
- To keep only Netcode for GameObjects synchronization, remove the **GhostObject** component.
84+
- To keep only Unity Netcode synchronization, remove the **NetworkObject** component.
85+
86+
> [!NOTE]
87+
> Unity might prevent you from removing a **GhostObject** or **NetworkObject** component while the GameObject has `GhostBehaviour` or `NetworkBehaviour` components that depend on it. Remove the dependent components first.
88+
89+
## Additional resources
90+
91+
- [GhostObjects in Unity Netcode](https://docs.unity3d.com/Packages/com.unity.netcode@latest?subfolder=/manual/ghostobject/ghostobject.html)
92+
- [Unity Netcode documentation](https://docs.unity3d.com/Packages/com.unity.netcode@latest)
93+
- [NetworkObject](components/core/networkobject.md)
94+
- [NetworkObject parenting](advanced-topics/networkobject-parenting.md)
95+
- [Physics](advanced-topics/physics.md)

‎com.unity.netcode.gameobjects/Runtime/Connection/NetworkConnectionManager.cs‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1085,7 +1085,6 @@ internal void HandleConnectionApproval(ulong ownerClientId, bool createPlayerObj
10851085
if (NetworkManager.DistributedAuthorityMode && NetworkManager.DAHost)
10861086
{
10871087
NetworkManager.SetSessionOwner(NetworkManager.LocalClientId);
1088-
NetworkManager.SceneManager.InitializeScenesLoaded();
10891088
}
10901089

10911090
if (NetworkManager.DistributedAuthorityMode && NetworkManager.AutoSpawnPlayerPrefabClientSide)

‎com.unity.netcode.gameobjects/Runtime/Core/NetworkManager.cs‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,11 @@ internal void SetSessionOwner(ulong sessionOwner)
232232
var isSessionOwner = LocalClientId == sessionOwner;
233233
LocalClient.IsSessionOwner = isSessionOwner;
234234

235+
if (isSessionOwner && NetworkConfig.EnableSceneManagement)
236+
{
237+
SceneManager.InitializeScenesLoaded();
238+
}
239+
235240
foreach (var networkObject in SpawnManager.SpawnedObjects.Values)
236241
{
237242
if (isSessionOwner)

‎com.unity.netcode.gameobjects/Runtime/Messaging/Messages/ConnectionApprovedMessage.cs‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -281,10 +281,6 @@ public void Handle(ref NetworkContext context)
281281
networkManager.SetSessionOwner(GetSessionOwner());
282282
if (networkManager.LocalClient.IsSessionOwner)
283283
{
284-
if (networkManager.NetworkConfig.EnableSceneManagement)
285-
{
286-
networkManager.SceneManager.InitializeScenesLoaded();
287-
}
288284
if (networkManager.NetworkConfig.ConnectionApproval && networkManager.LogLevel <= LogLevel.Developer)
289285
{
290286
NetworkLog.LogWarning($"{nameof(NetworkConfig.ConnectionApproval)} is enabled but is not supported when using a distributed authority topology. The {nameof(NetworkManager.ConnectionApprovalCallback)} will not be invoked.");

0 commit comments

Comments
 (0)