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/learn/bitesize/bitesize-spaceshooter.md
+4-5
Original file line number
Diff line number
Diff line change
@@ -4,15 +4,15 @@ title: 2D Space Shooter Sample
4
4
description: Learn more about physics movement and status effects using Netcode for GameObjects (Netcode) NetworkVariables and ObjectPooling .
5
5
---
6
6
7
-
The [2D Space Shooter Project](https://github.com/Unity-Technologies/com.unity.multiplayer.samples.bitesize/tree/master/Basic/2DSpaceShooter) provides examples of physics, player health, and status effects using Netcode for GameObjects (Netcode). Technical features include[NetworkVariable](../../basics/networkvariable.md) and [ObjectPooling](../../advanced-topics/object-pooling.md).
7
+
The [2D Space Shooter Project](https://github.com/Unity-Technologies/com.unity.multiplayer.samples.bitesize/tree/master/Basic/2DSpaceShooter) provides examples of physics, player health, and status effects using Netcode for GameObjects (Netcode). Technical features include[NetworkVariable](../../basics/networkvariable.md) and [ObjectPooling](../../advanced-topics/object-pooling.md).
8
8
9
-
## Server Authorative Physics Movement
9
+
## Server Authoritative Physics Movement
10
10
11
11
The movement in 2DSpaceShooter is physics based. The player object is a dynamic rigidbody and can collide with other players or asteroids. Physics in multiplayer games can be hard to get right. For simplicity, 2DSpaceShooter runs all movement and physics just on the server-side.
12
12
13
13
The client sends inputs in the form of RPCs to the server. The server then uses those inputs to adjust the throttle and turn values of the player.
14
14
15
-
This method of running physics makes sure that there are no desyncs or other physics issues between the client and server, but it introduces more latency.
15
+
This method of running physics makes sure that there are no desyncs or other physics issues between the client and server, but it introduces more latency.
The `2DSpaceShooter` object creates many objects dynamically at runtime including bullets, asteroids, and pickups. 2DSpaceShooter uses object pooling to avoid performance issues of instantiating and destroying Unity Objects all the time and creating allocations in the process.
42
42
43
-
2DSpaceShooter uses the NetworkObjectPool script, which can be found in the Community Contributions Repository.
43
+
2DSpaceShooter uses the NetworkObjectPool script, which can be found in the Community Contributions Repository.
If you are using Unity 2021, you can use the built-in [Object Pooling API](https://docs.unity3d.com/2021.1/Documentation/ScriptReference/Pool.ObjectPool_1.html) instead to build your own object pools.
Copy file name to clipboardExpand all lines: docs/learn/listenserverhostarchitecture.md
+14-13
Original file line number
Diff line number
Diff line change
@@ -11,29 +11,29 @@ A listen server is hosted on one of the player's machine. It acts both as a serv
11
11
12
12
### Disadvantages
13
13
14
-
- Network Performance is impacted by having to communicate with remote players over the residential internet connection of the host player.
15
-
- Network Performance may also be reduced because the machine running the server is also generating an output image.
14
+
- Network Performance is impacted by having to communicate with remote players over the residential internet connection of the host player.
15
+
- Network Performance may also be reduced because the machine running the server is also generating an output image.
16
16
- Listen servers grant the host player a large latency advantage over other players.
17
-
- The hosting client has access to all the world's information, making it easier to cheat for that player.
17
+
- The hosting client has access to all the world's information, making it easier to cheat for that player.
18
18
- The server will cease to exist when host player leaves the game.
19
19
20
-
### Advantages
20
+
### Advantages
21
21
22
-
- Essentially free
22
+
- Essentially free
23
23
- Don't require any special infrastructure or forward planning to set up, which makes them common at LAN parties where latency and bandwidth issues aren't a concern.
24
24
25
25
## When to use a listen server architecture
26
26
27
-
The listen server architecture is a popular option for single player games which want to add the option to add a friend into an existing world. Listen servers work best for a smaller amount of players (< 12) and for games which don't need persistent worlds because the game state is often tied to the host.
27
+
The listen server architecture is a popular option for single player games which want to add the option to add a friend into an existing world. Listen servers work best for a smaller amount of players (< 12) and for games which don't need persistent worlds because the game state is often tied to the host.
28
28
29
29
:::info
30
30
Persistent world in netcode usually means "persistent online world' For example, the game state isn't bound to a player or a session
31
31
:::
32
32
33
-
Listen servers are also much cheaper then dedicated servers because there is no need to run dedicated authorative servers for your game. Often developers chose a listen server approach because they don't want to deal with setting up a system which orchestrates their game server fleet.
33
+
Listen servers are also much cheaper then dedicated servers because there is no need to run dedicated authoritative servers for your game. Often developers chose a listen server approach because they don't want to deal with setting up a system which orchestrates their game server fleet.
34
34
35
35
:::note
36
-
You will still have to setup matchmaking to get your players to join together. You can't just launch a listen server game and get players playing together, you still have to redirect players to those client-hosted servers.
36
+
You will still have to setup matchmaking to get your players to join together. You can't just launch a listen server game and get players playing together, you still have to redirect players to those client-hosted servers.
37
37
:::
38
38
39
39
:::funfact
@@ -47,13 +47,14 @@ Connecting to someone elses computer is often not as straight forward as one wou
47
47
### Option A: Port Forwarding
48
48
49
49
Often the host can forward a public port on his router to a machine in his local network and thus allow someone from the outside to connect to a listen server. While this approach works fine it comes with a few caveats.
50
+
50
51
1. Users need to manually open ports on their router and there is quite a bit of technical knowledge needed to do so.
51
52
1. Users won't always have access to their routers. For instance if they use a mobile device or are using a corporate network or public WIFI.
52
53
53
-
These limitations make port forwarding often not a viable option for a released game but it can be a useful tool for development. You can learn more about how to port forward here: https://portforward.com/
54
+
These limitations make port forwarding often not a viable option for a released game but it can be a useful tool for development. You can learn more about how to port forward here: https://portforward.com/
54
55
55
56
:::caution
56
-
There are risks associated port forwarding. If you open ports, then you are opening direct lines for hackers and malware attacks. it's recommended that you close the ports when you have completed your session.
57
+
There are risks associated port forwarding. If you open ports, then you are opening direct lines for hackers and malware attacks. it's recommended that you close the ports when you have completed your session.
57
58
:::
58
59
59
60
### Option B: Relay server
@@ -70,7 +71,7 @@ The idea behind NAT Punchthrough is to open a direct connection between clients
70
71
71
72
### Option D: NAT Punch and Relay Fallback
72
73
73
-
This option combines NAT punching with a relay fallback. The idea is to first have clients try connecting to the host via NAT punching and if the connection fails they default back to the relay server. This helps to reduce load on the relay while still allowing any client to connect to the host. This option is widely used because
74
+
This option combines NAT punching with a relay fallback. The idea is to first have clients try connecting to the host via NAT punching and if the connection fails they default back to the relay server. This helps to reduce load on the relay while still allowing any client to connect to the host. This option is widely used because
74
75
it reduces hosting costs of relay servers.
75
76
76
77
## Which option to chose
@@ -81,7 +82,7 @@ Many platforms come with platform specific networking solutions. They usually us
81
82
82
83
There are companies which provide relay servers in your cloud ready for your game to use such as Playfab Party or Photon Realtime. They usually charge a cost based on the CCU (conccurrent users).
83
84
84
-
## Netcode for GameObjects (Netcode) and listen servers
85
+
## Netcode for GameObjects (Netcode) and listen servers
85
86
86
87
Netcode modular transport system supports all the options above. Most regular transports will allow you to connect to them
87
-
via port forwarding. Netcode can support platform specific relays via Transport. You can find implementations in the Netcode-community-contributions repository. Netcode also supports cross platform listen servers by integrating a third party relay service via transport. You can also write your own Relay server or NAT punch server for Netcode.
88
+
via port forwarding. Netcode can support platform specific relays via Transport. You can find implementations in the Netcode-community-contributions repository. Netcode also supports cross platform listen servers by integrating a third party relay service via transport. You can also write your own Relay server or NAT punch server for Netcode.
Copy file name to clipboardExpand all lines: versioned_docs/version-0.1.0/basics/object-spawning.md
+12-13
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,7 @@ sidebar_label: Object Spawning
6
6
7
7
:::contribution Community Contribution
8
8
9
-
There is a Video Tutorial covering some of the concepts covered in this page [here](../learn/dapper/objectspawning.md)
9
+
There is a Video Tutorial covering some of the concepts covered in this page [here](../learn/dapper/objectspawning.md)
10
10
:::
11
11
12
12
In Unity, you typically create a new game object using the `Instantiate` function. Creating a game object with `Instantiate` will only create that object on that player's local machine. `Spawning` in MLAPI means to create an object which is shared between all clients and the server.
@@ -16,15 +16,15 @@ In Unity, you typically create a new game object using the `Instantiate` functio
16
16
To spawn an object, it must first be registered as a networked prefab:
17
17
18
18
1. Create a Prefab out of the object you want to spawn.
19
-
1. Make sure the object has a `NetworkObject` component on it.
19
+
1. Make sure the object has a `NetworkObject` component on it.
20
+
21
+
The `NetworkObject` component has a `PrefabHash` this is a unique name used by MLAPI to find the right object to spawn on the clients. By default this is the name of the object but it can be changed if needed.
20
22
21
-
The `NetworkObject` component has a `PrefabHash` this is a unique name used by MLAPI to find the right object to spawn on the clients. By default this is the name of the object but it can be changed if needed.
22
-
23
23
1. Add your Prefab to the `NetworkPrefabs` list of the `NetworkManager`.
24
24
25
25
### Spawning a Networked Prefab
26
26
27
-
MLAPI uses a server authorative networking model so spawning objects can only be done on the server/host.
27
+
MLAPI uses a server authoritative networking model so spawning objects can only be done on the server/host.
28
28
To spawn an object first instantiate the object from your Prefab and then invoke the spawn method on the `NetworkObject` component that should be attached to the prefab.
29
29
This should only be done on the server as the object will automatically replicate on the other clients.
30
30
By default a newly spawned object is owned by the server. See [Ownership](networkobject.md#ownership) for more information.
@@ -42,10 +42,10 @@ The `.Spawn()` method takes 2 optional parameters, both with default values:
|`spawnPayload`| A `System.IO.Stream` and can be retrieved in `NetworkStart()` to sync values once when spawning this object. The payload data is only available for already connected clients. If a client connects later they won't get the payload data. |
48
-
|`destroyWithScene`| If set to true, the object will be destroyed on scene switching. This can only be set inside the spawn call. |
|`spawnPayload`| A `System.IO.Stream` and can be retrieved in `NetworkStart()` to sync values once when spawning this object. The payload data is only available for already connected clients. If a client connects later they won't get the payload data. |
48
+
|`destroyWithScene`| If set to true, the object will be destroyed on scene switching. This can only be set inside the spawn call. |
49
49
50
50
## Destroying / Despawning
51
51
@@ -57,15 +57,15 @@ When a client disconnects, all objects owned by that client will be destroyed. I
57
57
58
58
To despawn a networked object on all clients but keep it on the server call `NetworkObject.Despawn` on the server. An despawned object can also later be spawned again with another spawn call if needed.
59
59
60
-
A client should never call destroy on a networked object itself (this isn't supported). To destroy an object with client authority, have the client send an RPC to the server, which allows the server to destroy the object.
60
+
A client should never call destroy on a networked object itself (this isn't supported). To destroy an object with client authority, have the client send an RPC to the server, which allows the server to destroy the object.
61
61
62
62
You can't despawn objects on just specific clients. If you want to hide an object on some clients but display it on others use [Object Visibility](object-visibility.md).
63
63
64
64
To get more control about the object lifecycle, MLAPI has built in object pooling. See [Object Pooling](../advanced-topics/object-pooling.md) to learn more.
65
65
66
66
## Scene Objects
67
67
68
-
Any objects in the scene with active `NetworkObject` components will get automatically replicated by MLAPI. There is no need to manually spawn them.
68
+
Any objects in the scene with active `NetworkObject` components will get automatically replicated by MLAPI. There is no need to manually spawn them.
69
69
70
70
There are **two** modes that define how scene objects are synchronized.
71
71
@@ -76,10 +76,9 @@ There are **two** modes that define how scene objects are synchronized.
76
76
When using `SoftSync` MLAPI will just synchronize existing scene objects with each other.
77
77
This allows scene objects to be non prefabs and they won't be replaced, thus keeping their serialized data.
78
78
79
-
80
79
### PrefabSync
81
80
82
-
`PrefabSync` can be manually enabled in the `NetworkManager` by ticking the *Use Prefab Sync* checkbox. Prefab sync will also be used if `SceneManagement` is disabled.
81
+
`PrefabSync` can be manually enabled in the `NetworkManager` by ticking the _Use Prefab Sync_ checkbox. Prefab sync will also be used if `SceneManagement` is disabled.
83
82
84
83
If it's enabled, every scene object with a `NetworkObject` component has to be a Prefab and must be registered in the `NetworkPrefabs` list. When a client starts, MLAPI will destroy all existing scene objects with a `NetworkObject` component on them and spawn a corresponding Prefab from the `NetworkPrefabs` list instead. This means that serialized data gets lost on the clients. It's thus recommended to place serialized data in `NetworkVariable`'s.
85
84
**PrefabSync is ONLY recommended for multi project setups**.
Copy file name to clipboardExpand all lines: versioned_docs/version-0.1.0/learn/bitesize-spaceshooter.md
+4-4
Original file line number
Diff line number
Diff line change
@@ -4,9 +4,9 @@ title: 2D Space Shooter Sample
4
4
description: Learn more about physics movement and status effects using MLAPI NetworkVariables and ObjectPooling using MLAPI.
5
5
---
6
6
7
-
The [2D Space Shooter Project](https://github.com/Unity-Technologies/com.unity.multiplayer.samples.bitesize/tree/master/Basic/2DSpaceShooter) provides examples of physics, player health, and status effects using Unity MLAPI. Technical features include `NetworkVariable` and `ObjectPooling`.
7
+
The [2D Space Shooter Project](https://github.com/Unity-Technologies/com.unity.multiplayer.samples.bitesize/tree/master/Basic/2DSpaceShooter) provides examples of physics, player health, and status effects using Unity MLAPI. Technical features include `NetworkVariable` and `ObjectPooling`.
8
8
9
-
## Server Authorative Physics Movement
9
+
## Server Authoritative Physics Movement
10
10
11
11
The movement in 2DSpaceShooter is physics based. The player object is a dynamic rigidbody and can collide with other players or asteroids. Physics in multiplayer games can be hard to get right. For simplicity, 2DSpaceShooter runs all movement and physics just on the server-side.
The `2DSpaceShooter` object creates many objects dynamically at runtime including bullets, asteroids, and pickups. 2DSpaceShooter uses object pooling to avoid performance issues of instantiating and destroying Unity Objects all the time and creating allocations in the process.
42
42
43
-
2DSpaceShooter uses the [NetworkObjectPool](https://github.com/Unity-Technologies/mlapi-community-contributions/tree/master/com.mlapi.contrib.extensions/Runtime/NetworkObjectPool) script, which can be found in the Community Contributions Repository.
43
+
2DSpaceShooter uses the [NetworkObjectPool](https://github.com/Unity-Technologies/mlapi-community-contributions/tree/master/com.mlapi.contrib.extensions/Runtime/NetworkObjectPool) script, which can be found in the Community Contributions Repository.
If you are using Unity 2021, you can use the built-in [Object Pooling API](https://docs.unity3d.com/2021.1/Documentation/ScriptReference/Pool.ObjectPool_1.html) instead to build your own object pools.
0 commit comments