Skip to content

Commit 138fb38

Browse files
Merge branch 'fix/networktransform-autoswitchspace-forcing-updates-localspace' into doc/addition-to-3664-order-of-operations
2 parents 7df4646 + b4f85f2 commit 138fb38

File tree

10 files changed

+32
-29
lines changed

10 files changed

+32
-29
lines changed

com.unity.netcode.gameobjects/CHANGELOG.md

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,17 @@ Additional documentation and release notes are available at [Multiplayer Documen
1010

1111
### Added
1212

13-
- Added a `Set` function onto `NetworkList` that takes an optional parameter that forces an update to be processed even if the current value is equal to the previous value. (#3690)
1413
- Added NetworkRigidbody documentation section. (#3664)
15-
- Clicking on the Help icon in the inspector will now redirect to the relevant documentation. (#3663)
16-
- `NetworkSceneManager` as an internal wrapper for the `SceneManager.Scene.handle` and swapped all places that use an `int` to represent a `Scene.handle` to instead use the `NetworkSceneManager`. (#3647)
1714

1815
### Changed
1916

2017
- The `NetworkManager` functions `GetTransportIdFromClientId` and `GetClientIdFromTransportId` will now return `ulong.MaxValue` when the clientId or transportId do not exist. (#3707)
21-
- Improved performance of the NetworkVariable. (#3683)
22-
- Improved performance around the NetworkBehaviour component. (#3687)
2318
- Changed NetworkShow to send a message at the end of the frame and force a NetworkVariable synchronization prior to generating the CreateObjectMessage as opposed to waiting until the next network tick to synchronize the show with the update to NetworkVariables. (#3664)
2419
- Changed NetworkTransform now synchronizes `NetworkTransform.SwitchTransformSpaceWhenParented` when it is updated by the motion model authority. (#3664)
2520
- Changed when NetworkObjects pending to be shown to clients can now occur on partial network ticks. If any pending NetworkObjects pending to be shown to clients happens to be ready on a new network tick they still are shown after network variable deltas have been processed. (#3664)
2621
- Changed the default `NetworkDelivery` used by all messages is now reliable fragmented sequenced with the exception of named, unnamed, and any messages sent with a user specified network delivery type. This assures certain order of operations to be preserved when same call-stack changes are applied to a newly spawned, authority side, NetworkObject. (#3664)
2722
- Changed NetworkTransform documentation to better reflect the Teleport methods intended usage along with updates to NetworkObject and physics areas of the documentation. (#3664)
23+
- The first session owner no longer sends two synchronization messages to the service. (#3563)
2824

2925
### Deprecated
3026

@@ -35,8 +31,6 @@ Additional documentation and release notes are available at [Multiplayer Documen
3531
### Fixed
3632

3733
- Multiple disconnect events from the same transport will no longer disconnect the host. (#3707)
38-
- Distributed authority clients no longer send themselves in the `ClientIds` list when sending a `ChangeOwnershipMessage`. (#3687)
39-
- Made a variety of small performance improvements. (#3683)
4034
- Fixed NetworkTransform state synchronization issue when `NetworkTransform.SwitchTransformSpaceWhenParented` is enabled and the associated NetworkObject is parented multiple times in a single frame or within a couple of frames. (#3664)
4135
- Fixed issue when spawning, parenting, and immediately re-parenting when `NetworkTransform.SwitchTransformSpaceWhenParented` is enabled. (#3664)
4236
- Fixed issue where the disconnect event and provided message was too generic to know why the disconnect occurred. (#3551)

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,6 @@
3535
* [NetworkRigidbody](components/helper/networkrigidbody.md)
3636
* [NetworkTransform](components/helper/networktransform.md)
3737
* [Physics](advanced-topics/physics.md)
38-
* [Ownership and authority](ownership-authority.md)
39-
* [Understanding ownership and authority](basics/ownership.md)
40-
* [Ownership race conditions](basics/race-conditions.md)
4138
* [Spawning and despawning](spawn-despawn.md)
4239
* [Object spawning](basics/object-spawning.md)
4340
* [Network prefab handler](advanced-topics/network-prefab-handler.md)

com.unity.netcode.gameobjects/Documentation~/components/core/networkbehaviour.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ Dynamically spawned | In-scene placed (disabled NetworkBehaviour components)
6666
`OnNetworkSpawn` | `OnNetworkSpawn`
6767
`Start` | `Start` (invoked when disabled NetworkBehaviour components are enabled)
6868

69-
> [!NOTE] Parenting, inactive GameObjects, and NetworkBehaviour components
69+
> [!NOTE]
70+
> Parenting, inactive GameObjects, and NetworkBehaviour components<br />
7071
> If you have child GameObjects that are not active in the hierarchy but are nested under an active GameObject with an attached NetworkObject component, then the inactive child GameObjects will not be included when the NetworkObject is spawned. This applies for the duration of the NetworkObject's spawned lifetime. If you want all child NetworkBehaviour components to be included in the spawn process, then make sure their respective GameObjects are active in the hierarchy before spawning the NetworkObject. Alternatively, you can just disable the NetworkBehaviour component(s) individually while leaving their associated GameObject active.
7172
> It's recommended to disable a NetworkBehaviour component rather than the GameObject itself.
7273
@@ -165,7 +166,8 @@ Each NetworkBehaviour has a virtual `OnDestroy` method that you can override to
165166
}
166167
```
167168

168-
> [!NOTE] Destroying the GameObject
169+
> [!NOTE]
170+
> Destroying the GameObject<br />
169171
> When destroying a NetworkObject from within an associated NetworkBehaviour component script, you should always destroy the `NetworkObject.gameObject` and not the `NetworkBehaviour.gameObject` in case the NetworkBehaviour is located on a child GameObject nested under the NetworkObject's GameObject.
170172
171173
### Despawn process and invocation order

com.unity.netcode.gameobjects/Documentation~/components/core/networkobject.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,14 @@ The default `NetworkObject.Spawn` method assumes server-side ownership:
4141
GetComponent<NetworkObject>().Spawn();
4242
```
4343

44-
To spawn NetworkObjects with ownership use the following:
44+
To spawn a `NetworkObject` that is [owned](../../terms-concepts/ownership.md) by a different game client than the one doing the spawning, use the following:
4545

4646
```csharp
4747
GetComponent<NetworkObject>().SpawnWithOwnership(clientId);
4848
```
4949
> [!NOTE]
50-
> When using the `SpawnWithOwnership` method, be aware that any component that has owner-specific checks to perform specific actions won't be invoked on the spawn authority side during the spawn sequence. The spawn authority is the server when using a client-server network topology, and can be any client when using a distributed authority network topology. Using `SpawnWithOwnership` can impact things like [NetworkTransform](../helper/networktransform.md) when using an owner authority motion model, and potentially provide undesired parenting artifacts and/or impact your own scripts if you are planning to have the spawn authority make any further post-spawn adjustments within the same frame.
51-
> To avoid potential issues, it's recommended to use `Spawn`, where the spawn authority starts as the owner throughout the spawn sequence, makes adjustments post-spawn, and then immediately follow with a call to `ChangeOwnership`.
50+
> The `SpawnWithOwnership` method allows a game client to spawn an object that it doesn't own. This means any owner-specific checks during the spawn sequence will not be invoked on the spawn authority side. Using `SpawnWithOwnership` can result in unexpected behavior if the spawn authority makes any additional post-spawn adjustments within the same frame.
51+
> To avoid potential issues, it's recommended to use `Spawn` if the spawn authority needs to make any adjustments post-spawn. After adjusting, the spawn authority can immediately follow with a call to `ChangeOwnership`.
5252
5353
To change ownership, use the `ChangeOwnership` method:
5454

@@ -62,7 +62,7 @@ To give ownership back to the server use the `RemoveOwnership` method:
6262
GetComponent<NetworkObject>().RemoveOwnership();
6363
```
6464
> [!NOTE]
65-
> Using `RemoveOwnership` in a distributed authority network topology isn't recommended.
65+
> `RemoveOwnership` isn't supported when using a [distributed authority network topology](../../terms-concepts/distributed-authority.md).
6666
6767

6868
To see if the local client is the owner of a NetworkObject, you can check the [`NetworkBehaviour.IsOwner`](https://docs.unity3d.com/Packages/com.unity.netcode.gameobjects@latest?subfolder=/api/Unity.Netcode.NetworkBehaviour.IsOwner.html) property.

com.unity.netcode.gameobjects/Documentation~/components/helper/networkanimator.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,5 +121,6 @@ public void SetPlayerJumping(bool isJumping)
121121
}
122122
```
123123

124-
> [!NOTE] Changing meshes
124+
> [!NOTE]
125+
> Changing meshes<br/>
125126
> When swapping a skinned mesh with another reparented skinned mesh, you can invoke the `Rebind ` method on the `Animator` components: `Animator.Rebind()`.
6.52 KB
Loading

com.unity.netcode.gameobjects/Runtime/Components/NetworkTransform.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1515,7 +1515,7 @@ internal bool SynchronizeScale
15151515
/// <remarks>
15161516
/// Only works with <see cref="NetworkTransform"/> components that are not paired with a <see cref="NetworkRigidbody"/> or <see cref="NetworkRigidbody2D"/> component that is configured to use the rigid body for motion.<br />
15171517
/// <see cref="TickSyncChildren"/> will automatically be set when this is enabled.
1518-
/// This field is auto-synchronize with non-authority clients if changed by the authority instance.
1518+
/// This field is auto-synchronized with non-authority clients when changed by the authority instance.
15191519
/// </remarks>
15201520
[Tooltip("When enabled, NetworkTransform controls world or local space settings while also providing smooth parenting transitions." +
15211521
"When disabled, world or local space settings have to be adjusted by script or in the inspector view.")]

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

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,11 @@ internal void SetSessionOwner(ulong sessionOwner)
236236
OnSessionOwnerPromoted?.Invoke(sessionOwner);
237237
}
238238

239+
#if ENABLE_SESSIONOWNER_PROMOTION_NOTIFICATION
240+
public void PromoteSessionOwner(ulong clientId)
241+
#else
239242
internal void PromoteSessionOwner(ulong clientId)
243+
#endif
240244
{
241245
if (!DistributedAuthorityMode)
242246
{
@@ -253,10 +257,18 @@ internal void PromoteSessionOwner(ulong clientId)
253257
{
254258
SessionOwner = clientId,
255259
};
256-
var clients = ConnectionManager.ConnectedClientIds.Where(c => c != LocalClientId).ToArray();
257-
foreach (var targetClient in clients)
260+
var delivery = MessageDeliveryType<SessionOwnerMessage>.DefaultDelivery;
261+
if (CMBServiceConnection)
258262
{
259-
ConnectionManager.SendMessage(ref sessionOwnerMessage, MessageDeliveryType<SessionOwnerMessage>.DefaultDelivery, targetClient);
263+
ConnectionManager.SendMessage(ref sessionOwnerMessage, delivery, ServerClientId);
264+
}
265+
else
266+
{
267+
var clients = ConnectionManager.ConnectedClientIds.Where(c => c != LocalClientId).ToArray();
268+
foreach (var targetClient in clients)
269+
{
270+
ConnectionManager.SendMessage(ref sessionOwnerMessage, delivery, targetClient);
271+
}
260272
}
261273
}
262274

com.unity.netcode.gameobjects/Runtime/HelpUrls.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ internal static class HelpUrls
1010
public const string NetworkManager = k_BaseManualUrl + "components/core/networkmanager.html";
1111
public const string NetworkObject = k_BaseManualUrl + "components/core/networkobject.html";
1212
public const string NetworkAnimator = k_BaseManualUrl + "components/helper/networkanimator.html";
13-
public const string NetworkRigidbody = k_BaseManualUrl + "advanced-topics/physics.html#networkrigidbody";
14-
public const string NetworkRigidbody2D = k_BaseManualUrl + "advanced-topics/physics.html#networkrigidbody2d";
13+
public const string NetworkRigidbody = k_BaseManualUrl + "components/helper/networkrigidbody.html";
14+
public const string NetworkRigidbody2D = k_BaseManualUrl + "components/helper/networkrigidbody.html";
1515
public const string RigidbodyContactEventManager = k_BaseApiUrl + ".Components.RigidbodyContactEventManager.html";
1616
public const string NetworkTransform = k_BaseManualUrl + "components/helper/networktransform.html";
1717
public const string AnticipatedNetworkTransform = k_BaseManualUrl + "advanced-topics/client-anticipation.html";

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -373,21 +373,18 @@ public void Handle(ref NetworkContext context)
373373

374374
if (!networkManager.SceneManager.IsRestoringSession)
375375
{
376-
// Synchronize the service with the initial session owner's loaded scenes and spawned objects
377-
networkManager.SceneManager.SynchronizeNetworkObjects(NetworkManager.ServerClientId, true);
378-
379376
// Spawn any in-scene placed NetworkObjects
380377
networkManager.SpawnManager.ServerSpawnSceneObjectsOnStartSweep();
381378

379+
// Synchronize the service with the initial session owner's loaded scenes and spawned objects
380+
networkManager.SceneManager.SynchronizeNetworkObjects(NetworkManager.ServerClientId, true);
381+
382382
// Spawn the local player of the session owner
383383
if (networkManager.AutoSpawnPlayerPrefabClientSide)
384384
{
385385
networkManager.ConnectionManager.CreateAndSpawnPlayer(OwnerClientId);
386386
}
387387

388-
// Synchronize the service with the initial session owner's loaded scenes and spawned objects
389-
networkManager.SceneManager.SynchronizeNetworkObjects(NetworkManager.ServerClientId, true);
390-
391388
// With scene management enabled and since the session owner doesn't send a scene event synchronize to itself,
392389
// we need to notify the session owner that everything should be synchronized/spawned at this time.
393390
networkManager.SpawnManager.NotifyNetworkObjectsSynchronized();

0 commit comments

Comments
 (0)