Skip to content

Commit 3c6f655

Browse files
author
Larah Armstrong
authored
Fix issue #998 (#999)
2 parents 37a23f7 + acf9701 commit 3c6f655

12 files changed

+172
-163
lines changed

docs/basics/object-spawning.md

+30-27
Large diffs are not rendered by default.

docs/learn/bitesize/bitesize-spaceshooter.md

+4-5
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ title: 2D Space Shooter Sample
44
description: Learn more about physics movement and status effects using Netcode for GameObjects (Netcode) NetworkVariables and ObjectPooling .
55
---
66

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).
88

9-
## Server Authorative Physics Movement
9+
## Server Authoritative Physics Movement
1010

1111
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.
1212

1313
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.
1414

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.
1616

1717
## Player Health
1818

@@ -40,7 +40,7 @@ https://github.com/Unity-Technologies/com.unity.multiplayer.samples.bitesize/blo
4040

4141
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.
4242

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.
4444

4545
![pool img](/img/bitesize/invader-networkobjectpool.png)
4646

@@ -67,4 +67,3 @@ powerUp.GetComponent<NetworkObject>().Spawn(null, true);
6767
:::tip
6868
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.
6969
:::
70-

docs/learn/listenserverhostarchitecture.md

+14-13
Original file line numberDiff line numberDiff line change
@@ -11,29 +11,29 @@ A listen server is hosted on one of the player's machine. It acts both as a serv
1111

1212
### Disadvantages
1313

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.
1616
- 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.
1818
- The server will cease to exist when host player leaves the game.
1919

20-
### Advantages
20+
### Advantages
2121

22-
- Essentially free
22+
- Essentially free
2323
- 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.
2424

2525
## When to use a listen server architecture
2626

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.
2828

2929
:::info
3030
Persistent world in netcode usually means "persistent online world' For example, the game state isn't bound to a player or a session
3131
:::
3232

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.
3434

3535
:::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.
3737
:::
3838

3939
:::funfact
@@ -47,13 +47,14 @@ Connecting to someone elses computer is often not as straight forward as one wou
4747
### Option A: Port Forwarding
4848

4949
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+
5051
1. Users need to manually open ports on their router and there is quite a bit of technical knowledge needed to do so.
5152
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.
5253

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/
5455

5556
:::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.
5758
:::
5859

5960
### Option B: Relay server
@@ -70,7 +71,7 @@ The idea behind NAT Punchthrough is to open a direct connection between clients
7071

7172
### Option D: NAT Punch and Relay Fallback
7273

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
7475
it reduces hosting costs of relay servers.
7576

7677
## Which option to chose
@@ -81,7 +82,7 @@ Many platforms come with platform specific networking solutions. They usually us
8182

8283
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).
8384

84-
## Netcode for GameObjects (Netcode) and listen servers
85+
## Netcode for GameObjects (Netcode) and listen servers
8586

8687
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.

versioned_docs/version-0.1.0/basics/object-spawning.md

+12-13
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ sidebar_label: Object Spawning
66

77
:::contribution Community Contribution
88

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)
1010
:::
1111

1212
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
1616
To spawn an object, it must first be registered as a networked prefab:
1717

1818
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.
2022

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-
2323
1. Add your Prefab to the `NetworkPrefabs` list of the `NetworkManager`.
2424

2525
### Spawning a Networked Prefab
2626

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.
2828
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.
2929
This should only be done on the server as the object will automatically replicate on the other clients.
3030
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:
4242
public void Spawn(Stream spawnPayload = null, bool destroyWithScene = false);
4343
```
4444

45-
| Parameter | Description |
46-
| -- | -- |
47-
| `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. |
45+
| Parameter | Description |
46+
| ------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
47+
| `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. |
4949

5050
## Destroying / Despawning
5151

@@ -57,15 +57,15 @@ When a client disconnects, all objects owned by that client will be destroyed. I
5757

5858
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.
5959

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.
6161

6262
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).
6363

6464
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.
6565

6666
## Scene Objects
6767

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.
6969

7070
There are **two** modes that define how scene objects are synchronized.
7171

@@ -76,10 +76,9 @@ There are **two** modes that define how scene objects are synchronized.
7676
When using `SoftSync` MLAPI will just synchronize existing scene objects with each other.
7777
This allows scene objects to be non prefabs and they won't be replaced, thus keeping their serialized data.
7878

79-
8079
### PrefabSync
8180

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.
8382

8483
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.
8584
**PrefabSync is ONLY recommended for multi project setups**.

versioned_docs/version-0.1.0/learn/bitesize-spaceshooter.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ title: 2D Space Shooter Sample
44
description: Learn more about physics movement and status effects using MLAPI NetworkVariables and ObjectPooling using MLAPI.
55
---
66

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`.
88

9-
## Server Authorative Physics Movement
9+
## Server Authoritative Physics Movement
1010

1111
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.
1212

@@ -40,7 +40,7 @@ https://github.com/Unity-Technologies/com.unity.multiplayer.samples.bitesize/blo
4040

4141
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.
4242

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.
4444

4545
![pool img](/img/bitesize/invader-networkobjectpool.png)
4646

@@ -66,4 +66,4 @@ powerUp.GetComponent<NetworkObject>().Spawn(null, true);
6666

6767
:::tip
6868
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.
69-
:::
69+
:::

0 commit comments

Comments
 (0)