Skip to content

feat: AttachableBehaviour and ComponentController #3518

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 50 commits into
base: develop-2.0.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
43906be
update
NoelStephensUnity May 22, 2025
6267a3e
update
NoelStephensUnity May 28, 2025
83ee650
update
NoelStephensUnity May 28, 2025
3914204
Merge branch 'develop-2.0.0' into feat/attachable-networkbehaviour-an…
NoelStephensUnity May 28, 2025
41b14b5
Merge branch 'develop-2.0.0' into feat/attachable-networkbehaviour-an…
NoelStephensUnity Jun 23, 2025
1832d21
refactor
NoelStephensUnity Jun 24, 2025
d08d496
test
NoelStephensUnity Jun 24, 2025
4a9775a
style
NoelStephensUnity Jun 24, 2025
1f81ebd
style - PVP
NoelStephensUnity Jun 24, 2025
4148bfe
style - standards
NoelStephensUnity Jun 24, 2025
2322d48
Merge branch 'develop-2.0.0' into feat/attachable-networkbehaviour-an…
NoelStephensUnity Jun 24, 2025
1fce513
refactor
NoelStephensUnity Jun 24, 2025
1ceb76c
update
NoelStephensUnity Jun 24, 2025
db05292
test
NoelStephensUnity Jun 24, 2025
2d391ed
test - update
NoelStephensUnity Jun 24, 2025
ae29873
style
NoelStephensUnity Jun 24, 2025
078bca1
Merge branch 'develop-2.0.0' into feat/attachable-networkbehaviour-an…
NoelStephensUnity Jun 24, 2025
ec59da9
Merge branch 'develop-2.0.0' into feat/attachable-networkbehaviour-an…
NoelStephensUnity Jul 10, 2025
043b0e7
update
NoelStephensUnity Jul 10, 2025
6e9530e
Merge branch 'develop-2.0.0' into feat/attachable-networkbehaviour-an…
NoelStephensUnity Jul 10, 2025
abd75d0
update
NoelStephensUnity Jul 10, 2025
e098e31
update
NoelStephensUnity Jul 13, 2025
cab1983
refactor
NoelStephensUnity Jul 13, 2025
1341aa0
style
NoelStephensUnity Jul 13, 2025
13d9a03
update & style
NoelStephensUnity Jul 13, 2025
8bd712c
refactor
NoelStephensUnity Jul 15, 2025
a63de0b
test
NoelStephensUnity Jul 15, 2025
17b769d
Merge branch 'develop-2.0.0' into feat/attachable-networkbehaviour-an…
NoelStephensUnity Jul 15, 2025
912b26f
update
NoelStephensUnity Jul 15, 2025
6d8f7a6
Merge branch 'develop-2.0.0' into feat/attachable-networkbehaviour-an…
NoelStephensUnity Jul 15, 2025
9dd32d5
update
NoelStephensUnity Jul 15, 2025
793cdb6
fix
NoelStephensUnity Jul 15, 2025
fb73b8c
style - PVP
NoelStephensUnity Jul 15, 2025
4b4c8ca
update
NoelStephensUnity Jul 18, 2025
42ac2a8
sty;e - PvP
NoelStephensUnity Jul 19, 2025
efcc404
update and test additions
NoelStephensUnity Jul 21, 2025
9b4bf43
Merge branch 'develop-2.0.0' into feat/attachable-networkbehaviour-an…
NoelStephensUnity Jul 21, 2025
741b42b
docs (update,, refactor. and fix)
NoelStephensUnity Jul 30, 2025
cc04caf
docs (style-PVP)
NoelStephensUnity Jul 30, 2025
8ad7a82
docs(style-pvp)
NoelStephensUnity Jul 30, 2025
959ccef
docs (update & add)
NoelStephensUnity Jul 30, 2025
7c95cc7
docs (style - PVP)
NoelStephensUnity Jul 30, 2025
3866464
Merge branch 'develop-2.0.0' into feat/attachable-networkbehaviour-an…
NoelStephensUnity Jul 30, 2025
fe88923
docs (style)
NoelStephensUnity Jul 30, 2025
5662003
Update com.unity.netcode.gameobjects/Runtime/Core/NetworkObject.cs
NoelStephensUnity Jul 30, 2025
93b645f
update
NoelStephensUnity Jul 30, 2025
e9eec54
style
NoelStephensUnity Jul 30, 2025
a2d8703
Merge branch 'develop-2.0.0' into feat/attachable-networkbehaviour-an…
NoelStephensUnity Jul 30, 2025
db4adab
Lorge doc review
jabbacakes Aug 1, 2025
ea66904
Merge branch 'develop-2.0.0' into feat/attachable-networkbehaviour-an…
NoelStephensUnity Aug 5, 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
4 changes: 2 additions & 2 deletions Examples/CharacterControllerMovingBodies/Readme.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Netcode for GameObjects Smooth Transform Space Transitions
## Non-Rigidbody CharacterController Parenting with Moving Bodies
![image](https://github.com/user-attachments/assets/096953ca-5d7d-40d5-916b-72212575d258)
This example provides you with the fundamental building blocks for smooth synchronized transitions between two non-rigidbody based objects. This includes transitioning from world to local, local to world, and local to local transform spaces.
This example provides you with the fundamental building blocks for smooth synchronized transitions between two non-rigidbody based objects. This includes transitioning from world to local, local to world, and local to local transform spaces.

### The `CharacterController`
![image](https://github.com/user-attachments/assets/13c627bd-920d-40c8-8947-69aa37b44ebf)
The `CharacterController` component is assigned to the `PlayerNoRigidbody` player prefab. It includes a `MoverScriptNoRigidbody` that handles all of the player's motion and includes some additional "non-rigidbody to non-rigidbody" collision handling logic that is applied when a player bumps into a rotation and/or moving body. The player prefab includes a child "PlayerBallPrime" that rotates around the player in local space (nested `NetworkTransform`), and the "PlayerBallPrime" has 3 children ("PlayerBallChild1-3") that each rotates around a different axis of the "PlayerBallPrime". While the end resulting effect is kind of cool looking, they provide a point of reference as to whether there is any deviation of each child's given axial path relative to each parent level. Additionally, it shows how tick synchronized nested `NetworkTransform` components keep synchronized with their parent and how that persists when the parent is parented or has its parent removed.
The `CharacterController` component is assigned to the `PlayerNoRigidbody` player prefab. It includes a `MoverScriptNoRigidbody` that handles all of the player's motion and includes some additional "non-rigidbody to non-rigidbody" collision handling logic that is applied when a player bumps into a rotation and/or moving body. The player prefab includes a child "PlayerBallPrime" that rotates around the player in local space (nested NetworkTransform), and the "PlayerBallPrime" has 3 children ("PlayerBallChild1-3") that each rotates around a different axis of the "PlayerBallPrime". While the end resulting effect is kind of cool looking, they provide a point of reference as to whether there is any deviation of each child's given axial path relative to each parent level. Additionally, it shows how tick synchronized nested NetworkTransform components keep synchronized with their parent and how that persists when the parent is parented or has its parent removed.

### Rotating Bodies
#### StationaryBodyA&B
Expand Down
30 changes: 15 additions & 15 deletions Examples/OverridingScenesAndPrefabs/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ _Supports using the client-server and distributed authority network topologies._

This example, based on the [Netcode for GameObjects Smooth Transform Space Transitions](https://github.com/Unity-Technologies/com.unity.netcode.gameobjects/tree/example/server-client-unique-scenes-and-prefabs/Examples/CharacterControllerMovingBodies), provides and overview of how to use:
- [`NetworkPrefabHandler`](https://docs.unity3d.com/Packages/[email protected]/api/Unity.Netcode.NetworkPrefabHandler.html) as a way to dynamically control overriding network prefabs and how they are instantiated.
- For this example, the prefab handler is overriding the player prefab.
- For this example, the prefab handler is overriding the player prefab.
- *You will only see the end result of this portion of the example by running a server instance (i.e. not host) as that will create instances of the ServerPlayer network prefab instead of the ClientPlayer network prefab.*
- [`NetworkSceneManager.SetClientSynchronizationMode`](https://docs.unity3d.com/Packages/[email protected]/api/Unity.Netcode.NetworkSceneManager.html#Unity_Netcode_NetworkSceneManager_SetClientSynchronizationMode_UnityEngine_SceneManagement_LoadSceneMode_) to change the default client synchronization mode (SingleMode) to an additive client synchronization mode.
- Additive client synchronization mode will prevent already existing preloaded scenes from being unloaded and will use them, as opposed to reloading the same scene, during a client's initial synchronization.
- [`NetworkSceneManager.SetClientSynchronizationMode`](https://docs.unity3d.com/Packages/[email protected]/api/Unity.Netcode.NetworkSceneManager.html#Unity_Netcode_NetworkSceneManager_SetClientSynchronizationMode_UnityEngine_SceneManagement_LoadSceneMode_) to change the default client synchronization mode (SingleMode) to an additive client synchronization mode.
- Additive client synchronization mode will prevent already existing preloaded scenes from being unloaded and will use them, as opposed to reloading the same scene, during a client's initial synchronization.
- *This is a server-side only setting that gets sent to the clients during the initial synchronization process.*
- [`NetworkSceneManager.VerifySceneBeforeLoading`](https://docs.unity3d.com/Packages/[email protected]/api/Unity.Netcode.NetworkSceneManager.html#Unity_Netcode_NetworkSceneManager_VerifySceneBeforeLoading) in order to control what scenes the server will include when sending the synchronization message to newly connecting clients.

Expand All @@ -19,14 +19,14 @@ This example uses unity services. Upon loading the project for the first time, y
## Terminology

### Shared Scenes
These are scenes that will be synchronized between a server or session owner and used when a client runs through the initial synchronization process.
- You can populate these scenes with in-scene placed or dynamically spawned NetworkObjects.
These are scenes that will be synchronized between a server or session owner and used when a client runs through the initial synchronization process.
- You can populate these scenes with in-scene placed or dynamically spawned NetworkObjects.
- These scenes **must be** within the scenes in build list.

### Local Scenes
These are scenes that are always only local to the application instances (server or client) and will not be synchronized.
- You should not populate these scenes with NetworkObjects.
-However, this example includes one of several ways you can associate a `MonoBehaviour` with a `NetworkBehaviour`.
These are scenes that are always only local to the application instances (server or client) and will not be synchronized.
- You should not populate these scenes with NetworkObjects.
-However, this example includes one of several ways you can associate a `MonoBehaviour` with a NetworkBehaviour.
- These scenes can be dynamically created, included in the scenes in build list, or be an addressable loaded at some point prior to connecting or while connected to a session.

## Client Synchronization and Scene Validation
Expand Down Expand Up @@ -54,16 +54,16 @@ The first scene loaded. Contains a `NetworkManagerBootstrapper` in-scene placed
#### NetworkManager Bootstrapper (component)
![image](Images/NetworkManagerBootstrapperProperties.png)

Handles the pre-network session menu interface along with connect and disconnect events. Since it is derived from `NetworkManager`, it also defines the network session configuration (i.e. `NetworkConfig`). The `NetworkManagerBootstrapper` in-scene placed `GameObject` gets loaded into the DDOL scene automatically and will persist throughout the application life time. This derived class requires the `SceneBootstrapLoader` component.
Handles the pre-network session menu interface along with connect and disconnect events. Since it is derived from NetworkManager, it also defines the network session configuration (i.e. `NetworkConfig`). The `NetworkManagerBootstrapper` in-scene placed `GameObject` gets loaded into the DDOL scene automatically and will persist throughout the application life time. This derived class requires the `SceneBootstrapLoader` component.

#### Scene Bootstrap Loader (component)
![image](Images/SceneBootstrapLoader.png)

This component handles preloading scenes for both the client(s) and server. Upon being started, the `NetworkManagerBootstrapper` component will invoke `SceneBootstrapLoader.LoadMainMenu` method that kicks off the scene preloading process.
This component handles preloading scenes for both the client(s) and server. Upon being started, the `NetworkManagerBootstrapper` component will invoke `SceneBootstrapLoader.LoadMainMenu` method that kicks off the scene preloading process.
- **Default Active Scene Asset:** There is always an active scene. For this example, the default active scene is the same on both the client and server relative properties. *The active scene is always (and should always) be a "shared scene".*
- This could represent a lobby or network session main menu (i.e. create or join session).
- Both the client and the server preload this scene prior to starting a network session.
- **Local Scene Assets:** There could be times where you want to load scenes specific to the `NetworkManager` instance type (i.e. client, host, or server).
- **Local Scene Assets:** There could be times where you want to load scenes specific to the NetworkManager instance type (i.e. client, host, or server).
- These scenes are not synchronized by a server (client-server) or session owner (distributed authority).
- Having different locally loaded scenes is typically more common in a client-server network topology.
- In a distributed authority network topology, it is more common to keep all scenes synchronized but you might want to load non-synchronized scenes (i.e. menu interface for settings etc).
Expand All @@ -72,11 +72,11 @@ This component handles preloading scenes for both the client(s) and server. Upon
- If the server synchronizes any scenes from the share scene assets with a client that already has those scene loaded, then those locally loaded scenes on the client side will be used during synchronization.
- Depending upon how many scenes you want to synchronize and/or how large one or more scenes are, preloading scenes can reduce synchronization time for clients.
The `NetworkManagerBootstrapper` uses the `SceneBootstrapLoader` component to start the creation or joining of a network session. The logical flow looks like:
- `NetworkManagerBootstrapper` invokes `SceneBootstrapLoader.StartSession` when you click one of the (very simple) main menu buttons and passes in the mode/type of `NetworkManager` to start.
- Based on the `NetworkManager` type being started, the `SceneBootstrapLoader` will then:
- `NetworkManagerBootstrapper` invokes `SceneBootstrapLoader.StartSession` when you click one of the (very simple) main menu buttons and passes in the mode/type of NetworkManager to start.
- Based on the NetworkManager type being started, the `SceneBootstrapLoader` will then:
- Load the default active scene using the `UnityEngine.SceneManagement.SceneManager`.
- Load the local scenes using the `UnityEngine.SceneManagement.SceneManager`.
- Then it will create or join a network session by either starting the `NetworkManager` or connecting to the sesssion via multiplayer services.
- Then it will create or join a network session by either starting the NetworkManager or connecting to the sesssion via multiplayer services.
- _Server or Session Owner only:_
- If any, load the shared (i.e. synchronized) scene assets using the `NetworkSceneManager`

Expand All @@ -87,7 +87,7 @@ This `MonoBehaviour` component implements the `INetworkPrefabInstanceHandler` in
- Network Prefab: This is the network prefab that you want to override. In this example, it is what is used to spawn a server-side player prefab and is what is defined within the `NetworkManagerBootstrapper` component.
- Network Prefab Override: This is what is used to spawn a player prefab on the client-side.

At runtime the local `NetworkManager` instance is a client/host or server and will spawn either the ClientPlayer or ServerPlayer prefab. The `NetworkPrefabOverrideHandler` does not need to be a `NetworkBehaviour` and sometimes (especially for overriding the player prefab) it is better to register prefab handlers prior to starting the `NetworkManager`.
At runtime the local NetworkManager instance is a client/host or server and will spawn either the ClientPlayer or ServerPlayer prefab. The `NetworkPrefabOverrideHandler` does not need to be a NetworkBehaviour and sometimes (especially for overriding the player prefab) it is better to register prefab handlers prior to starting the NetworkManager.

## Input Controls
The following is a list of the input controls used in this project:
Expand Down
Loading