You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/advanced-topics/transports.md
+91Lines changed: 91 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -22,6 +22,97 @@ A transport layer can provide:
22
22
23
23
Netcode's default transport Unity Transport is an entire transport layer that you can use to add multiplayer and network features to your project with or without Netcode. Refer to the [Transport documentation](https://docs-multiplayer.unity3d.com/transport/current/about/) for more information and how to [install the Transport package](https://docs-multiplayer.unity3d.com/transport/current/install/).
24
24
25
+
## `SinglePlayerTransport`
26
+
27
+
Netcode for GameObjects provides a `SinglePlayerTransport` that you can use to create a local single player network session. This simplifies switching between multiplayer and single player sessions within the same project, while still being able to use existing netcode scripts. The `SinglePlayerTransport` is a effectively a mock transport that ensures full `NetworkTransport` functionality without any transport dependencies.
28
+
29
+
### Set up a single player session
30
+
31
+
In addition to your default network transport, you need to add the `SinglePlayerTransport` to the `NetworkManager``GameObject` (or child of).
To start a single player session, assign the `SinglePlayerTransport` to the `NetworkManager.NetworkConfig.NetworkTransport` configuration property using a script.
NetworkLog.LogError("Failed to start single player session!");
63
+
}
64
+
}
65
+
66
+
publicvoidStartHostedSession()
67
+
{
68
+
// Use the network transport when starting a multiplayer session.
69
+
NetworkConfig.NetworkTransport=m_UnityTransport;
70
+
if (!StartHost())
71
+
{
72
+
NetworkLog.LogError("Failed to start hosted session!");
73
+
}
74
+
}
75
+
}
76
+
```
77
+
78
+
As shown in the script above, when starting a single player session the `SinglePlayerTransport` is assigned to the `NetworkConfig.NetworkTransport`, and when starting a hosted multiplayer session the `UnityTransport` is assigned.
79
+
80
+
### Single player limitations
81
+
82
+
When running a single player session, you should take any netcode script into consideration that requires an actual multiplayer session to exist.
83
+
84
+
#### RPC considerations
85
+
You can invoke any RPC that includes:
86
+
87
+
- The host's client.
88
+
- The host's server.
89
+
-`SendTo` targets that will be invoked locally:
90
+
-`SendTo.Me`
91
+
-`SendTo.Server`
92
+
-`SendTo.Everyone`
93
+
-`SendTo.Authority`
94
+
-`SendTo.Owner`
95
+
-`ClientsAndHost`
96
+
-`SpecifiedInParams`: As long as it is targeting the `NetworkManager.LocalClientId`.
97
+
-`SendTo` targets that will **not be** invoked locally:
98
+
-`SendTo.NotOwner`
99
+
-`SendTo.NotServer`
100
+
-`SendTo.NotMe`
101
+
-`SendTo.NotAuthority`
102
+
-`SpecifiedInParams`: Anything not targeting the `NetworkManager.LocalClientId` will not be invoked locally.
103
+
104
+
#### NetworkVariable considerations
105
+
106
+
NetworkVariables should work as expected because the host will always be both the server and the owner of anything spawned. This means that write permissions, whether server or owner, should not be an issue.
107
+
108
+
#### Distributed authority considerations
109
+
110
+
To start a single player session using the distributed authority network topology you should:
111
+
- Keep your network topology setting set to distributed authority.
112
+
- Set the `NetworkConfig.NetworkTransport` to the `SinglePlayerTransport` component.
113
+
- Start as a host.
114
+
115
+
25
116
## Unity's UNet transport layer API
26
117
27
118
UNet is a deprecated solution that is no longer supported after Unity 2022.2. Unity Transport Package is the default transport for Netcode for GameObjects. We recommend transitioning to Unity Transport as soon as possible.
0 commit comments