Skip to content

Commit d9af8fc

Browse files
authored
Merge pull request #268 from jaglitegrann/bug/check-islistening-before-object-spawn
fix(spawning): Add check for NetworkingManager.IsListening before spa…
2 parents 28309b5 + a243d2a commit d9af8fc

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

MLAPI/Core/NetworkedObject.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,11 @@ private void OnDestroy()
387387
/// <param name="destroyWithScene">Should the object be destroyd when the scene is changed</param>
388388
public void Spawn(Stream spawnPayload = null, bool destroyWithScene = false)
389389
{
390+
if (!NetworkingManager.Singleton.IsListening)
391+
{
392+
throw new NotListeningException("NetworkingManager isn't listening, start a server, client or host before spawning objects.");
393+
}
394+
390395
if (spawnPayload != null)
391396
spawnPayload.Position = 0;
392397

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using System;
2+
3+
namespace MLAPI.Exceptions
4+
{
5+
/// <summary>
6+
/// Exception thrown when the operation require NetworkingManager to be listening.
7+
/// </summary>
8+
public class NotListeningException : Exception
9+
{
10+
/// <summary>
11+
/// Constructs a NotListeningException
12+
/// </summary>
13+
public NotListeningException()
14+
{
15+
16+
}
17+
18+
/// <summary>
19+
/// Constructs a NotListeningException with a message
20+
/// </summary>
21+
/// <param name="message">The exception message</param>
22+
public NotListeningException(string message) : base(message)
23+
{
24+
25+
}
26+
27+
/// <summary>
28+
/// Constructs a NotListeningException with a message and a inner exception
29+
/// </summary>
30+
/// <param name="message">The exception message</param>
31+
/// <param name="inner">The inner exception</param>
32+
public NotListeningException(string message, Exception inner) : base(message, inner)
33+
{
34+
35+
}
36+
}
37+
}

0 commit comments

Comments
 (0)