Skip to content

Commit eb9104d

Browse files
committed
Updated documentation to explain soft sync
1 parent 259bbb2 commit eb9104d

File tree

7 files changed

+58
-56
lines changed

7 files changed

+58
-56
lines changed

docs/_docs/advanced-topics/object-pooling.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@ This can be achieved by registering custom spawn and destroy handlers.
1010

1111
### SpawnHandler
1212
```csharp
13-
SpawnManager.RegisterCustomSpawnHandler(SpawnManager.GetPrefabHash("myPrefabName"), (position, rotation, disabled) {
13+
SpawnManager.RegisterCustomSpawnHandler(SpawnManager.GetPrefabHash("myPrefabName"), (position, rotation, disabled) =>
14+
{
1415
// Called when the MLAPI want's to spawn a prefab with the name "myPrefabName"
1516
});
1617
```
1718
### DestroyHandler
1819
```csharp
19-
SpawnManager.RegisterCustomDestroyHandler(SpawnManager.GetPrefabHash("myPrefabName"), (networkedObject) {
20+
SpawnManager.RegisterCustomDestroyHandler(SpawnManager.GetPrefabHash("myPrefabName"), (networkedObject) =>
21+
{
2022
// Called when the MLAPI want's to destroy the given NetworkedObject
2123
});
2224
```

docs/_docs/core-components/networked-behaviour.md

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,4 @@ title: Networked Behaviour
33
permalink: /wiki/networked-behaviour/
44
---
55

6-
NetworkedBehaviour is a abstract class that derives from MonoBehaviour, it's the base class all your networked scripts should derive from. It's what provides messaging functionality and much more. Each NetworkedBehaviour will belong to a NetworkedObject, it will be the first parent or first component on the current object that is found.
7-
8-
9-
## Properties
10-
##### isLocalPlayer
11-
This returns true if this is the player object of our own client.
12-
##### isOwner
13-
This returns true if we own this object.
14-
##### isOwnedByServer
15-
Returns true if this object is owned by the server.
16-
##### isServer
17-
Returns true if we are a server.
18-
##### isClient
19-
Returns true if we are a client.
20-
#### isHost
21-
Returns true if we are a host.
22-
#### NetworkId
23-
Returns the NetworkId of the NetworkedObject that owns this Behaviour.
24-
#### OwnerClientId
25-
Returns the clientId of the Owner of this object
6+
NetworkedBehaviour is a abstract class that derives from MonoBehaviour, it's the base class all your networked scripts should derive from. It's what provides messaging functionality and much more. Each NetworkedBehaviour will belong to a NetworkedObject, it will be the first parent or first component on the current object that is found.

docs/_docs/getting-started/connection-approval.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,26 @@ However, when ConnectionApproval is true you are also required to provide a call
99
```csharp
1010
private void Setup()
1111
{
12-
NetworkingManager.singleton.ConnectionApprovalCallback = ApprovalCheck;
13-
NetworkingManager.singleton.StartHost();
12+
NetworkingManager.Singleton.ConnectionApprovalCallback = ApprovalCheck;
13+
NetworkingManager.Singleton.StartHost();
1414
}
1515

1616
private void ApprovalCheck(byte[] connectionData, uint clientId, MLAPI.NetworkingManager.ConnectionApprovedDelegate callback)
1717
{
1818
//Your logic here
1919
bool approve = true;
2020

21-
int prefabId = SpawnManager.GetNetworkedPrefabIndexOfName("myPrefabName"); // The prefab index. Use -1 to use the default player prefab.
21+
ulong? prefabHash = SpawnManager.GetPrefabHashFromGenerator("MyPrefabHashGenerator"); // The prefab hash. Use null to use the default player prefab
2222
2323
//If approve is true, the connection gets added. If it's false. The client gets disconnected
24-
callback(clientId, prefabId, approve, positionToSpawnAt, rotationToSpawnWith);
24+
callback(clientId, prefabHash, approve, positionToSpawnAt, rotationToSpawnWith);
2525
}
2626
```
2727
### Connection data
2828
The connectionData parameter is any custom data of your choice that the client should send to the server. Usually, this should be some sort of ticket, room password or similar that will decide if a connection should be approved or not. The connectionData is specified on the Client side in the NetworkingConfig supplied when connecting. Example:
2929
```csharp
30-
NetworkingManager.singleton.NetworkConfig.ConnectionData = System.Text.Encoding.ASCII.GetBytes("room password");
31-
NetworkingManager.singleton.StartClient();
30+
NetworkingManager.Singleton.NetworkConfig.ConnectionData = System.Text.Encoding.ASCII.GetBytes("room password");
31+
NetworkingManager.Singleton.StartClient();
3232
```
3333
The ConnectionData will then be passed to the server and it will decide if the client will be approved or not.
3434

docs/_docs/getting-started/library-initialization.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ This mode runs a Server and a virtual Client connected to its own server.
1212

1313
Usage:
1414
```csharp
15-
NetworkingManager.singleton.StartHost();
15+
NetworkingManager.Singleton.StartHost();
1616
```
1717

1818

@@ -22,7 +22,7 @@ This mode runs a Client that connects to a Server or Host.
2222

2323
Usage:
2424
```csharp
25-
NetworkingManager.singleton.StartClient();
25+
NetworkingManager.Singleton.StartClient();
2626
```
2727

2828
### Server mode
@@ -31,5 +31,5 @@ This mode runs a Server which other Clients can connect to.
3131

3232
Usage:
3333
```csharp
34-
NetworkingManager.singleton.StartServer();
34+
NetworkingManager.Singleton.StartServer();
3535
```

docs/_docs/the-basics/messaging-system.md

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ private void Update()
2727
{
2828
if (GUI.Button("SendRandomInt"))
2929
{
30-
if (isServer)
30+
if (IsServer)
3131
{
3232
InvokeClientRpcOnEveryone(MyClientRPC, Random.Range(-50, 50));
3333
}
@@ -87,24 +87,28 @@ private void Update()
8787
{
8888
if (GUI.Button("SendRandomInt"))
8989
{
90-
if (isServer)
90+
if (IsServer)
9191
{
9292
using (PooledBitStream stream = PooledBitStream.Get())
9393
{
94-
BitWriter writer = new BitWriter(stream);
95-
writer.WriteInt32Packed(Random.Range(-50, 50));
94+
using (PooledBitWriter writer = PooledBitWriter.Get(stream))
95+
{
96+
writer.WriteInt32Packed(Random.Range(-50, 50));
9697

97-
InvokeClientRpcOnEveryone(MyClientRPC, stream);
98+
InvokeClientRpcOnEveryone(MyClientRPC, stream);
99+
}
98100
}
99101
}
100102
else
101103
{
102104
using (PooledBitStream stream = PooledBitStream.Get())
103105
{
104-
BitWriter writer = new BitWriter(stream);
105-
writer.WriteInt32Packed(Random.Range(-50, 50));
106+
using (PooledBitWriter writer = PooledBitWriter.Get(stream))
107+
{
108+
writer.WriteInt32Packed(Random.Range(-50, 50));
106109

107-
InvokeServerRpc(MyServerRpc, stream);
110+
InvokeServerRpc(MyServerRpc, stream);
111+
}
108112
}
109113
}
110114
}
@@ -113,19 +117,23 @@ private void Update()
113117
[ServerRPC]
114118
private void MyServerRPC(uint clientId, Stream stream) //This signature is REQUIRED for the performance mode
115119
{
116-
BitReader reader = new BitReader(stream);
117-
int number = reader.ReadInt32Packed();
118-
Debug.Log("The number recieved was: " + number);
119-
Debug.Log("This method ran on the server upon the request of a client");
120+
using (PooledBitReader reader = PooledBitReader.Get(stream))
121+
{
122+
int number = reader.ReadInt32Packed();
123+
Debug.Log("The number recieved was: " + number);
124+
Debug.Log("This method ran on the server upon the request of a client");
125+
}
120126
}
121127

122128
[ClientRPC]
123129
private void MyClientRPC(uint clientId, Stream stream) //This signature is REQUIRED for the performance mode
124130
{
125-
BitReader reader = new BitReader(stream);
126-
int number = reader.ReadInt32Packed();
127-
Debug.Log("The number recieved was: " + number);
128-
Debug.Log("This method ran on the client upon the request of the server");
131+
using (PooledBitReader reader = PooledBitReader.Get(stream))
132+
{
133+
int number = reader.ReadInt32Packed();
134+
Debug.Log("The number recieved was: " + number);
135+
Debug.Log("This method ran on the client upon the request of the server");
136+
}
129137
}
130138
```
131139

@@ -162,12 +170,15 @@ If you don't want to use the MLAPI's messaging. You don't have to. You can use a
162170
void Start()
163171
{
164172
//Recieving
165-
NetworkingManager.singleton.OnIncommingCustomMessage += ((clientId, stream) {
166-
BitReader reader = new BitReader(stream);
167-
string message = reader.ReadString(); //Example
173+
NetworkingManager.Singleton.OnIncommingCustomMessage += ((clientId, stream) =>
174+
{
175+
using (PooledBitReader reader = PooledBitReader.Get(stream))
176+
{
177+
string message = reader.ReadString(); //Example
178+
}
168179
});
169180

170181
//Sending
171-
NetworkingManager.singleton.SendCustomMessage(clientId, myStream, "myCustomChannel"); //Channel is optional.
182+
NetworkingManager.Singleton.SendCustomMessage(clientId, myStream, "myCustomChannel"); //Channel is optional.
172183
}
173184
```

docs/_docs/the-basics/object-ownership.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ The default behavior is that an object is owned by the server. To give ownership
1515
GetComponent<NetworkedObject>().RemoveOwnership();
1616
```
1717

18-
When you are owner of an object. You can check for ``isOwner`` in any NetworkedBehaviour, similar to how player objects can do ``isLocalPlayer``
18+
When you are owner of an object. You can check for ``IsOwner`` in any NetworkedBehaviour, similar to how player objects can do ``IsLocalPlayer``
1919

2020
## Object destruction
2121
When a client disconnects. All objects owned by that client will be destroyed. If you don't want that. (Ex. if you want the objects to be dropped), you can remove ownership just before they are destroyed.

docs/_docs/the-basics/object-spawning.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,19 @@ permalink: /wiki/object-spawning/
66
To spawn an object. Make sure the object is in the spawnable prefabs array. Then simply instantiate the object. And
77
invoke the spawn method on the NetworkedObject component that should be attached to the prefab. This should only be done on the server as the object will automatically replicate on the other clients.
88

9-
Any objects already on the server with NetworkedObject components (static scene objects) will get automatically replicated. When objects are spawned the position and rotation is synced. This means that serialized data gets lost on the clients. It's thus recommended to place serialized data in NetworkedVars.
10-
11-
129
Here is an example on how to spawn a object
1310
```csharp
1411
GameObject go = Instantiate(myPrefab, Vector3.zero, Quaternion.identity);
1512
go.GetComponent<NetworkedObject>().Spawn();
16-
```
13+
```
14+
15+
## Scene Objects
16+
Any objects already on the server with NetworkedObject components (static scene objects) will get automatically replicated.
17+
18+
There are **two** modes that define how scene objects are spawned. The first mode is *PrefabSync*. It can enabled in the NetworkConfig.
19+
20+
#### SoftSync
21+
If PrefabSync is disabled, the MLAPI will use SoftSync. This allows scene objects to be non prefabs and they will not be replaced, thus keeping their serialized data. **This mode is recommended for single project setups**. This is the default since MLAPI 6.
22+
23+
#### PrefabSync
24+
If it's enabled, every scene object has to be a prefab and scene objects are recreated on the client side. This means that serialized data gets lost on the clients. It's thus recommended to place serialized data in NetworkedVars. **This mode is ONLY recommended for Multi project setups**. This was the default before MLAPI 6.

0 commit comments

Comments
 (0)