Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
94 commits
Select commit Hold shift + click to select a range
5a83370
fix
NoelStephensUnity Sep 9, 2025
952a40b
fix
NoelStephensUnity Sep 10, 2025
983bd1b
update
NoelStephensUnity Sep 11, 2025
1d36492
Merge branch 'develop-2.0.0' into fix/networktransform-autoswitchspac…
NoelStephensUnity Sep 11, 2025
9adf1e5
update
NoelStephensUnity Sep 11, 2025
6440658
Merge branch 'fix/networktransform-autoswitchspace-forcing-updates-lo…
NoelStephensUnity Sep 11, 2025
46d1854
update
NoelStephensUnity Sep 11, 2025
197f4b0
update
NoelStephensUnity Sep 11, 2025
7ab9dc1
Doc pass on NetworkTransform additions
jabbacakes Sep 12, 2025
d3347bd
fix
NoelStephensUnity Sep 12, 2025
b26de65
Merge branch 'fix/networktransform-autoswitchspace-forcing-updates-lo…
NoelStephensUnity Sep 12, 2025
db33128
Update com.unity.netcode.gameobjects/Runtime/Core/NetworkObject.cs
NoelStephensUnity Sep 12, 2025
ba36860
Update com.unity.netcode.gameobjects/Runtime/Components/NetworkTransf…
NoelStephensUnity Sep 12, 2025
ddc7c36
Update com.unity.netcode.gameobjects/Runtime/Components/NetworkTransf…
NoelStephensUnity Sep 12, 2025
c489e6f
Update com.unity.netcode.gameobjects/Runtime/Components/NetworkTransf…
NoelStephensUnity Sep 12, 2025
ae61807
Merge branch 'develop-2.0.0' into fix/networktransform-autoswitchspac…
NoelStephensUnity Sep 12, 2025
2521520
refactor
NoelStephensUnity Sep 13, 2025
649b989
style
NoelStephensUnity Sep 13, 2025
a267896
style - PVP
NoelStephensUnity Sep 13, 2025
4605249
update
NoelStephensUnity Sep 13, 2025
4917d40
Merge branch 'develop-2.0.0' into fix/networktransform-autoswitchspac…
NoelStephensUnity Sep 15, 2025
1dc4e4f
update
NoelStephensUnity Sep 15, 2025
07731e5
update
NoelStephensUnity Sep 15, 2025
e444a1b
update
NoelStephensUnity Sep 15, 2025
25bfb07
update
NoelStephensUnity Sep 15, 2025
06f2ead
upate
NoelStephensUnity Sep 15, 2025
41f8c36
style
NoelStephensUnity Sep 15, 2025
ef5090f
test
NoelStephensUnity Sep 15, 2025
7d05df9
Apply suggestions from code review
NoelStephensUnity Sep 15, 2025
fb99ba2
doc: update
NoelStephensUnity Sep 16, 2025
0908d74
doc: style
NoelStephensUnity Sep 16, 2025
aef1185
style - PVP
NoelStephensUnity Sep 16, 2025
473fcd8
update
NoelStephensUnity Sep 16, 2025
885452a
fix
NoelStephensUnity Sep 16, 2025
e24aff1
test and style
NoelStephensUnity Sep 16, 2025
b0e4510
Merge branch 'develop-2.0.0' into fix/networktransform-autoswitchspac…
NoelStephensUnity Sep 16, 2025
0a35b95
update
NoelStephensUnity Sep 16, 2025
bc20e16
update
NoelStephensUnity Sep 16, 2025
5f34872
update
NoelStephensUnity Sep 16, 2025
cf27a00
update
NoelStephensUnity Sep 17, 2025
8af2c0e
Docs pass on new content
jabbacakes Sep 19, 2025
909be07
Reinstating note
jabbacakes Sep 19, 2025
a65d89e
Updating landing page
jabbacakes Sep 19, 2025
4df63ea
refactor
NoelStephensUnity Sep 19, 2025
99a33cf
Merge branch 'fix/networktransform-autoswitchspace-forcing-updates-lo…
NoelStephensUnity Sep 19, 2025
a4e8570
update
NoelStephensUnity Sep 19, 2025
400172f
Merge branch 'develop-2.0.0' into fix/networktransform-autoswitchspac…
NoelStephensUnity Sep 19, 2025
f8a8125
update
NoelStephensUnity Sep 19, 2025
1f435e0
update
NoelStephensUnity Sep 20, 2025
79b602a
fix
NoelStephensUnity Sep 20, 2025
dea7aae
fix
NoelStephensUnity Sep 20, 2025
d71ebca
fix
NoelStephensUnity Sep 20, 2025
6f87b1d
refactor
NoelStephensUnity Sep 20, 2025
44df5f4
style - PVP
NoelStephensUnity Sep 20, 2025
fdfa924
refactor
NoelStephensUnity Sep 21, 2025
6b3ca04
fix
NoelStephensUnity Sep 21, 2025
ed2300f
fix
NoelStephensUnity Sep 22, 2025
1b1417b
fix
NoelStephensUnity Sep 22, 2025
f8ea16b
Merge branch 'develop-2.0.0' into fix/networktransform-autoswitchspac…
NoelStephensUnity Sep 23, 2025
6b426bd
refactor and fix
NoelStephensUnity Sep 23, 2025
4721384
fix
NoelStephensUnity Sep 24, 2025
810d71b
fix
NoelStephensUnity Sep 24, 2025
dbb1700
Merge branch 'develop-2.0.0' into fix/networktransform-autoswitchspac…
NoelStephensUnity Sep 25, 2025
8fc12aa
update
NoelStephensUnity Sep 25, 2025
720e64e
fix
NoelStephensUnity Sep 25, 2025
f004cc6
fix
NoelStephensUnity Sep 25, 2025
6673c82
fix
NoelStephensUnity Sep 25, 2025
b73615c
fix
NoelStephensUnity Sep 26, 2025
22f87dd
test
NoelStephensUnity Sep 26, 2025
7ccaa51
style
NoelStephensUnity Sep 26, 2025
22728b7
test - fix
NoelStephensUnity Sep 26, 2025
5d1918c
fix and update
NoelStephensUnity Sep 27, 2025
04ab564
test
NoelStephensUnity Sep 27, 2025
6653712
style
NoelStephensUnity Sep 27, 2025
77cf501
style - PVP
NoelStephensUnity Sep 27, 2025
d118767
refactor
NoelStephensUnity Sep 27, 2025
11f49ff
fix
NoelStephensUnity Sep 27, 2025
cbe3d71
update
NoelStephensUnity Sep 27, 2025
1ba970a
style
NoelStephensUnity Sep 27, 2025
2e1c329
refactor
NoelStephensUnity Sep 30, 2025
43d7379
Merge branch 'develop-2.0.0' into fix/networktransform-autoswitchspac…
NoelStephensUnity Sep 30, 2025
c9ff4d1
update
NoelStephensUnity Sep 30, 2025
c945ffb
update
NoelStephensUnity Sep 30, 2025
b9a3a10
refactor
NoelStephensUnity Sep 30, 2025
5a56eef
fix
NoelStephensUnity Oct 1, 2025
158821c
fix
NoelStephensUnity Oct 2, 2025
37447b6
update
NoelStephensUnity Oct 2, 2025
1d40cad
Merge branch 'develop-2.0.0' into fix/networktransform-autoswitchspac…
NoelStephensUnity Oct 2, 2025
ea92fd7
fix
NoelStephensUnity Oct 6, 2025
3199d5a
Merge branch 'develop-2.0.0' into fix/networktransform-autoswitchspac…
NoelStephensUnity Oct 6, 2025
ad0e6b4
fix
NoelStephensUnity Oct 6, 2025
4588548
Merge branch 'develop-2.0.0' into fix/networktransform-autoswitchspac…
NoelStephensUnity Oct 7, 2025
2d8e1cc
fix
NoelStephensUnity Oct 7, 2025
62a0f1c
fix - refactor
NoelStephensUnity Oct 7, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Tools/scripts/Utils/general_utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Helper class for common operations."""
"""Helper class for common operations."""
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an artifact from earlier changes... just reflecting what it is currently in the main v2 branch.

#!/usr/bin/env python3
import json
import os
Expand Down
9 changes: 9 additions & 0 deletions com.unity.netcode.gameobjects/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,19 @@ Additional documentation and release notes are available at [Multiplayer Documen

### Added

- Added NetworkRigidbody documentation section. (#3664)
- Clicking on the Help icon in the inspector will now redirect to the relevant documentation. (#3663)
- 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)

### Changed

- Improved performance of the NetworkVariable. (#3683)
- Improved performance around the NetworkBehaviour component. (#3687)
- Changed NetworkTransform now synchronizes `NetworkTransform.SwitchTransformSpaceWhenParented` when it is updated by the motion model authority. (#3664)
- 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)
- 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)
- Changed NetworkTransform documentation to better reflect the Teleport methods intended usage along with updates to NetworkObject and physics areas of the documentation. (#3664)


### Deprecated

Expand All @@ -27,6 +33,9 @@ Additional documentation and release notes are available at [Multiplayer Documen
### Fixed

- Made a variety of small performance improvements. (#3683)
- 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)
- Fixed issue when spawning, parenting, and immediately re-parenting. (#3664)


### Security

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@
* [AttachableNode](components/helper/attachablenode.md)
* [ComponentController](components/helper/componentcontroller.md)
* [NetworkAnimator](components/helper/networkanimator.md)
* [NetworkRigidbody](components/helper/networkrigidbody.md)
* [NetworkTransform](components/helper/networktransform.md)
* [Physics](advanced-topics/physics.md)
* [Physics](advanced-topics/physics.md)
* [Ownership and authority](ownership-authority.md)
* [Understanding ownership and authority](basics/ownership.md)
* [Ownership race conditions](basics/race-conditions.md)
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ To spawn NetworkObjects with ownership use the following:
```csharp
GetComponent<NetworkObject>().SpawnWithOwnership(clientId);
```
> [!NOTE]
> 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.
> 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`.

To change ownership, use the `ChangeOwnership` method:

Expand All @@ -58,6 +61,9 @@ To give ownership back to the server use the `RemoveOwnership` method:
```csharp
GetComponent<NetworkObject>().RemoveOwnership();
```
> [!NOTE]
> Using `RemoveOwnership` in a distributed authority network topology isn't recommended.


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.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ Understand the helper components available to use in your Netcode for GameObject
| **[AttachableNode](attachablenode.md)**| Use an AttachableNode component to provide an attachment point for an [AttachableBehaviour](attachablebehaviour.md) component. |
| **[ComponentController](componentcontroller.md)**| Use a [ComponentController](https://docs.unity3d.com/Packages/com.unity.netcode.gameobjects@latest?subfolder=/api/Unity.Netcode.ComponentController.html) component to enable or disable one or more components depending on the authority state of the ComponentController and have those changes synchronized with non-authority instances. |
| **[NetworkAnimator](networkanimator.md)**| The NetworkAnimator component provides you with a fundamental example of how to synchronize animations during a network session. Animation states are synchronized with players joining an existing network session and any client already connected before the animation state changing. |
| **[NetworkRigidbody](networkrigidbody.md)**| NetworkRigidbody is a component that sets the Rigidbody of the GameObject into kinematic mode on all non-authoritative instances. |
| **[NetworkTransform](networktransform.md)**| [NetworkTransform](https://docs.unity3d.com/Packages/com.unity.netcode.gameobjects@latest?subfolder=/api/Unity.Netcode.Components.NetworkTransform.html) is a concrete class that inherits from [NetworkBehaviour](../core/networkbehaviour.md) and synchronizes [Transform](https://docs.unity3d.com/Manual/class-Transform.html) properties across the network, ensuring that the position, rotation, and scale of a [GameObject](https://docs.unity3d.com/Manual/working-with-gameobjects.html) are replicated to other clients. |
| **[Physics](../../advanced-topics/physics.md)**| Netcode for GameObjects has a built in approach which allows for server-authoritative physics where the physics simulation only runs on the server. |
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# NetworkRigidbody

NetworkRigidbody is a component that sets the Rigidbody of the GameObject into kinematic mode on all non-authoritative instances. Authority is determined by the [NetworkTransform component](networktransform.md) (required) attached to the same GameObject as the NetworkRigidbody. Whether the NetworkTransform is server authoritative (default) or owner authoritative, the NetworkRigidBody authority model will mirror it. That way, the physics simulation runs on the authoritative instance, and the resulting positions synchronize on the non-authoritative instances, each with their RigidBody being kinematic, without any interference.

## Configure NetworkRigidbody

![image](../../images/networktransform/NetworkRigidbody-fields.png)

When looking at a NetworkRigidbody in the Inspector view, there are three exposed values:

- __Use Rigid Body for Motion__
- When enabled and using a [NetworkTransform](networktransform.md), the NetworkTransform uses the PhysX position and rotation to synchronize changes during the `FixedUpdate` loop update stage.
- __Auto Update Kinematic State__
- When enabled, NetworkRigidbody automatically determines whether the current instance should be kinematic or non-kinematic.
- For custom solutions, you can opt to disable this field or derive from [NetworkRigidbodyBase](https://docs.unity3d.com/Packages/[email protected]/api/Unity.Netcode.Components.NetworkRigidbodyBase.html) and design your own custom networked Rigidbody handler.
- __Auto Set Kinematic On Despawn__
- When enabled, this option makes the rigid body kinematic when despawned (which can be useful for [object pools](../../advanced-topics/object-pooling.md)).

Some collision events aren't fired when using NetworkRigidBody:

- On the server, all collision and trigger events (such as `OnCollisionEnter`) fire as expected and you can access (and change) values of the `Rigidbody` (such as velocity).
- On clients, Rigidbody is kinematic. Trigger events still fire but collision events won't fire when colliding with other networked Rigidbody instances if your project's physics settings is set to the default contact pairs.
![image](../../images/networktransform/ProjectPhysicsSettings.png)

- You can adjust the __Contact Pairs Mode__ to use kinematic and non-kinematic by setting it to __Enable All Contact Pairs__.![image](../../images/networktransform/ProjectPhysicsSettings2.png)

> [!NOTE]
> If there's a need for a gameplay event to happen on a collision, you can listen to the `OnCollisionEnter` function on the server and synchronize the event via `Rpc(SendTo.Everyone)` to all clients. If you plan on handling many collisions, then it's recommended to use the [RigidbodyContactEventManager component](https://docs.unity3d.com/Packages/com.unity.netcode.gameobjects@latest?subfolder=/api/Unity.Netcode.Components.RigidbodyContactEventManager.html) to handle collision checking during a job (`OnCollisionenter` can become expensive from a processing perspective if you have enough instances colliding).

### NetworkRigidbody2D

NetworkRigidbody2D works in the same way as NetworkRigidbody but for 2D physics (Rigidbody2D) instead.

## Rigidbody interpolation example

While NetworkTransform offers [interpolation](../../learn/clientside-interpolation.md) as a way to smooth between delta state updates, it doesn't get applied to the authoritative instance. You can use `Rigidbody.interpolation` for your authoritative instance while maintaining a strict server-authoritative motion model.

To have a client control their owned objects, you can use either [RPCs](../../advanced-topics/message-system/rpc.md) or [NetworkVariables](../../basics/networkvariable.md) on the client-side. However, this often results in the host-client's updates working as expected, but with slight jitter when a client sends updates. You might be scanning for key or device input during the `Update` to `LateUpdate` stages. Any input from the host player is applied after the `FixedUpdate` stage (such as physics simulation for the frame has already run), but input from client players is sent via a message and processed, with a half RTT delay, on the host side (or processed 1 network tick + half RTT if using NetworkVariables). Because of when messages are processed, client input updates run the risk of being processed during the `EarlyUpdate` stage which occurs just before the current frame's `FixedUpdate` stage.

To avoid this kind of scenario, it's recommended that you apply any changes received via messages to a Rigidbody after the `FixedUpdate` has run for the current frame. If you [refer to how NetworkTransform handles its changes to transform state](https://github.com/Unity-Technologies/com.unity.netcode.gameobjects/blob/a2c6f7da5be5af077427eef9c1598fa741585b82/com.unity.netcode.gameobjects/Components/NetworkTransform.cs#L3028), you can see that state updates are applied during the `Update` stage, but are received during the `EarlyUpdate` stage. Following this kind of pattern when synchronizing changes to a Rigidbody via messages will help you to avoid unexpected results in your Netcode for GameObjects project.

The best way to address the issue of physics latency is to create a custom NetworkTransform with a custom physics-based interpolator. You can also use the [Network Simulator tool](https://docs.unity3d.com/Packages/com.unity.multiplayer.tools@latest?subfolder=/manual/network-simulator) to spot issues with latency.
Loading