Skip to content

Commit 30cbf17

Browse files
committed
only register to the custom networked messages on clients
1 parent 43c8456 commit 30cbf17

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

Assets/BossRoom/Scripts/Shared/Infrastructure/PubSub/NetworkedMessageChannel.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ namespace Unity.Multiplayer.Samples.BossRoom.Shared.Infrastructure
77
{
88
/// <summary>
99
/// This type of message channel allows the server to publish a message that will be sent to clients as well as
10-
/// being published locally. Clients and the server both can subscribe to it, but it needs to be done after
11-
/// the NetworkManager is initialized.
10+
/// being published locally. Clients and the server both can subscribe to it. However, that subscription needs to be
11+
/// done after the NetworkManager has initialized. On objects whose lifetime is bigger than a networked session,
12+
/// subscribing will be required each time a new session starts.
1213
/// </summary>
1314
/// <typeparam name="T"></typeparam>
1415
public class NetworkedMessageChannel<T> : MessageChannel<T> where T : unmanaged
@@ -37,7 +38,8 @@ public override IDisposable Subscribe(Action<T> handler)
3738
{
3839
if (NetworkManager.Singleton != null && NetworkManager.Singleton.IsListening)
3940
{
40-
if (!m_HasRegisteredHandler && NetworkManager.Singleton.IsClient)
41+
// Only register message handler on clients
42+
if (!m_HasRegisteredHandler && !NetworkManager.Singleton.IsServer)
4143
{
4244
NetworkManager.Singleton.CustomMessagingManager.RegisterNamedMessageHandler(m_Name, ReceiveMessageThroughNetwork);
4345
m_HasRegisteredHandler = true;

0 commit comments

Comments
 (0)