Skip to content

Commit f6afc72

Browse files
committed
Merge branch 'master' of https://github.com/MidLevel/MLAPI
2 parents 37c45a8 + fbd31df commit f6afc72

File tree

12 files changed

+35
-15
lines changed

12 files changed

+35
-15
lines changed

MLAPI/Configuration/NetworkConfig.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ public byte[] ServerX509CertificateBytes
223223

224224
private void Sort()
225225
{
226-
RegisteredScenes.Sort();
226+
RegisteredScenes.Sort(StringComparer.Ordinal);
227227
}
228228

229229
/// <summary>

MLAPI/Core/NetworkedBehaviour.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ private static FieldInfo[] GetFieldInfoForTypeRecursive(Type type, List<FieldInf
258258
}
259259
else
260260
{
261-
return list.OrderBy(x => x.Name).ToArray();
261+
return list.OrderBy(x => x.Name, StringComparer.Ordinal).ToArray();
262262
}
263263
}
264264

MLAPI/Core/NetworkingManager.cs

+1-3
Original file line numberDiff line numberDiff line change
@@ -347,8 +347,6 @@ private void Init(bool server)
347347
SpawnManager.SpawnedObjectsList.Clear();
348348
SpawnManager.releasedNetworkObjectIds.Clear();
349349
SpawnManager.pendingSoftSyncObjects.Clear();
350-
SpawnManager.customSpawnHandlers.Clear();
351-
SpawnManager.customDestroyHandlers.Clear();
352350
NetworkSceneManager.registeredSceneNames.Clear();
353351
NetworkSceneManager.sceneIndexToString.Clear();
354352
NetworkSceneManager.sceneNameToIndex.Clear();
@@ -390,7 +388,7 @@ private void Init(bool server)
390388

391389
if (NetworkConfig.EnableSceneManagement)
392390
{
393-
NetworkConfig.RegisteredScenes.Sort();
391+
NetworkConfig.RegisteredScenes.Sort(StringComparer.Ordinal);
394392

395393
for (int i = 0; i < NetworkConfig.RegisteredScenes.Count; i++)
396394
{

MLAPI/Serialization/BitReader.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ public Quaternion ReadRotationPacked()
374374
float y = ReadSinglePacked();
375375
float z = ReadSinglePacked();
376376

377-
float w = Mathf.Sqrt(1 - ((Mathf.Pow(x, 2) - (Mathf.Pow(y, 2) - (Mathf.Pow(z, 2))))));
377+
float w = Mathf.Sqrt(1f - Mathf.Pow(x, 2) - Mathf.Pow(y, 2) - Mathf.Pow(z, 2));
378378

379379
return new Quaternion(x, y, z, w);
380380
}

MLAPI/Serialization/SerializationManager.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ internal static FieldInfo[] GetFieldsForType(Type type)
9898
FieldInfo[] fields = type
9999
.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)
100100
.Where(x => (x.IsPublic || x.GetCustomAttributes(typeof(SerializeField), true).Length > 0) && IsTypeSupported(x.FieldType))
101-
.OrderBy(x => x.Name).ToArray();
101+
.OrderBy(x => x.Name, StringComparer.Ordinal).ToArray();
102102

103103
fieldCache.Add(type, fields);
104104

MLAPI/Spawning/SpawnManager.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ internal static void ServerResetShudownStateForSceneObjects()
517517

518518
internal static void ServerDestroySpawnedSceneObjects()
519519
{
520-
for (int i = 0; i < SpawnedObjectsList.Count; i++)
520+
for (int i = SpawnedObjectsList.Count - 1; i >= 0; i--)
521521
{
522522
if ((SpawnedObjectsList[i].IsSceneObject != null && SpawnedObjectsList[i].IsSceneObject == true) || SpawnedObjectsList[i].DestroyWithScene)
523523
{

docs/_docs/advanced-topics/custom-transports.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ permalink: /wiki/custom-transports/
55

66
The MLAPI supports custom transports. It uses UNET by default. You can also write custom transports. A transport is the library that is responsible for sending the raw bytes and handle connections.
77

8-
Usually, transports doesn't support support all channel types and event types. Sometimes they have more, in that case you manually have to do translation between them. See the ENET transport for examples.
8+
Usually, transports doesn't support all channel types and event types. Sometimes they have more, in that case you manually have to do translation between them. See the ENET transport for examples.
99

1010
### Official Transports
1111
The MLAPI has some official transport implementations you can use. They can be found [here](https://github.com/midlevel/MLAPI.Transports). All you have to do is download the ZIP file you want from the CI server and export it into your assets folder and it will show up in the NetworkingManager automatically.
1212

1313

1414
### Writing Your Own
15-
To get started writing transport interfaces, the current implementations for Unet, ENET and Ruffles are great starting points for learning their flow. If you do write a transport for a well known transport, feel free to open a PR to add it to the official transports repo.
15+
To get started writing transport interfaces, the current implementations for Unet, ENET and Ruffles are great starting points for learning their flow. If you do write a transport for a well known transport, feel free to open a PR to add it to the official transports repo.

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ private void Start()
195195
private void Start()
196196
{
197197
//Receiving
198-
CustomMessagingManager.RegisterNamedMessageHandler("myMessageName", (senderClientId, stream)
198+
CustomMessagingManager.RegisterNamedMessageHandler("myMessageName", (senderClientId, stream) =>
199199
{
200200
using (PooledBitReader reader = PooledBitReader.Get(stream))
201201
{
@@ -207,4 +207,4 @@ private void Start()
207207
//Sending
208208
CustomMessagingManager.SendNamedMessage("myMessageName", clientId, myStream, "myCustomChannel"); //Channel is optional.
209209
}
210-
```
210+
```

docs/_docs/the-basics/networkedvar.md

+5
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ Since the NetworkedVar container is a wrapper container around the value, the va
2121

2222
To create your own NetworkedVar container, simply create a class with the INetworkedVar interface and declare it as a field of a NetworkedBehaviour. To learn how to write your own containers for more complex structures, see the NetworkedVar implementation. To learn how to do custom delta encoding on complex structures. See the SyncedDictionary and SyncedLIst implementations.
2323

24+
### Permissions
25+
By default NetworkedVar and it's subclasses can only be wrote to by the server (NetworkedVarPermission.ServerOnly). To change that set the permission to the desired value during initialization:
26+
```csharp
27+
private NetworkedVar<float> myFloat = new NetworkedVar(new NetworkedVarSettings {WritePermission = NetworkedVarPermission.OwnerOnly}, 5);
28+
```
2429

2530
### Example
2631
```csharp

docs/_docs/the-basics/object-behaviour-relation.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ The MLAPI's high level components (The RPC system and the Object Spawning System
99
For an object to be replicated across the network it needs to have a NetworkedObject component. It also has to be registered as a NetworkedPrefab. When a NetworkedObject is considered "Spawned", it's replicated across the network so that everyone has their own version of the object. Each NetworkedObject gets assigned a NetworkId at runtime which is used to associate two NetworkedObjects across the network. Ex: One peer can say, Send this RPC to the object with the NetworkId 103 and everyone knows what object that is.
1010

1111
### NetworkedBehaviour
12-
NetworkedBehaviour is an abstract class that inherits MonoBehaviour and adds additional functionality. Each NetworkedBehaviour is owned by a NetworkedObject. NetworkedBehaviours can contain RPC methods and NetworkedVars. When you call InvokeRPC, a message is sent containing your parameters, the networkId of the NetworkedObject that owns the NetworkedBehaviour that the Invoke was called on, and the "index" of the NetworkedBehaviour on the NetworkedObject. This means that if you run multiple projects, it's important that the order and amount of NetworkedBehaviours on each NetworkedObject is the same. It also means that NetworkedBehaviour's can only exist as a child or on the same object as a NetworkedObject that is activley Spawned.
12+
NetworkedBehaviour is an abstract class that inherits MonoBehaviour and adds additional functionality. Each NetworkedBehaviour is owned by a NetworkedObject. NetworkedBehaviours can contain RPC methods and NetworkedVars. When you call InvokeRPC, a message is sent containing your parameters, the networkId of the NetworkedObject that owns the NetworkedBehaviour that the Invoke was called on, and the "index" of the NetworkedBehaviour on the NetworkedObject. This means that if you run multiple projects, it's important that the order and amount of NetworkedBehaviours on each NetworkedObject is the same. It also means that NetworkedBehaviour's can only exist as a child or on the same object as a NetworkedObject that is actively Spawned.
1313

1414

1515
#### RPC Flow
@@ -30,4 +30,4 @@ Receive:
3030
- Reads RPC Method Name Hash
3131
- Finds The Method With The Hash Provided
3232
- Invokes It's Delegate With Parameters Or Body
33-
```
33+
```

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ The .Spawn() method takes 2 parameters, both with default values, so they are op
1616
```csharp
1717
public void Spawn(Stream spawnPayload = null, bool destroyWithScene = false);
1818
```
19-
The first parameter is a System.IO.Stream and can be retrieved in the NetworkStart() to sync values once when spawning this object. Note however, that the payload data is only avalible for people that get the spawn call straight away. People that join later on won't get the payload data.
19+
The first parameter is a System.IO.Stream and can be retrieved in the NetworkStart() to sync values once when spawning this object. Note however, that the payload data is only available for people that get the spawn call straight away. People that join later on won't get the payload data.
2020

2121
The second parameter speaks for itself. If set to true, the object will be destroyed on scene switching. This can only be set inside the spawn call.
2222

docs/_docs/troubleshooting/common-mistakes.md

+17
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ permalink: /wiki/common-mistakes/
66
This is a collection of common mistakes:
77

88
- [`NullReferenceException` when trying to start a server/host/client](#err-001)
9+
- [`NullReferenceException` when trying to send an RPC to the server](#err-002)
910

1011
---
1112

@@ -28,3 +29,19 @@ NullReferenceException: Object reference not set to an instance of an object
2829

2930
#### Solution
3031
You most likely forgot to add the `NetworkingManager` component to a game object in your scene.
32+
33+
---
34+
35+
### <a name="err-002"></a>`NullReferenceException` when trying to send an RPC to the server
36+
37+
#### Problem
38+
When the client tries to run `InvokeServerRpc`, the following exception is thrown:
39+
40+
```csharp
41+
NullReferenceException: Object reference not set to an instance of an object
42+
```
43+
44+
#### Solution
45+
You most likely forgot to `Spawn()` your object.
46+
47+
Run `Spawn()` on your `NetworkedObject` component as the server to fix this issue.

0 commit comments

Comments
 (0)