Skip to content
Open
Show file tree
Hide file tree
Changes from 41 commits
Commits
Show all changes
54 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
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
5 changes: 5 additions & 0 deletions com.unity.netcode.gameobjects/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@ Additional documentation and release notes are available at [Multiplayer Documen

### Added

- Added: NetworkRigidbody documentation section. (#3664)

### Changed

- Changed: NetworkTransform now synchronizes `NetworkTransform.SwitchTransformSpaceWhenParented` when it is updated by the motion model authority. (#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 @@ -22,6 +25,8 @@ Additional documentation and release notes are available at [Multiplayer Documen

### Fixed

- 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
@@ -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/com.unity.netcode.gameobjects@2.5/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