File tree Expand file tree Collapse file tree 1 file changed +5
-3
lines changed
Assets/BossRoom/Scripts/Shared/Infrastructure/PubSub Expand file tree Collapse file tree 1 file changed +5
-3
lines changed Original file line number Diff line number Diff line change @@ -7,8 +7,9 @@ namespace Unity.Multiplayer.Samples.BossRoom.Shared.Infrastructure
7
7
{
8
8
/// <summary>
9
9
/// 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.
12
13
/// </summary>
13
14
/// <typeparam name="T"></typeparam>
14
15
public class NetworkedMessageChannel < T > : MessageChannel < T > where T : unmanaged
@@ -37,7 +38,8 @@ public override IDisposable Subscribe(Action<T> handler)
37
38
{
38
39
if ( NetworkManager . Singleton != null && NetworkManager . Singleton . IsListening )
39
40
{
40
- if ( ! m_HasRegisteredHandler && NetworkManager . Singleton . IsClient )
41
+ // Only register message handler on clients
42
+ if ( ! m_HasRegisteredHandler && ! NetworkManager . Singleton . IsServer )
41
43
{
42
44
NetworkManager . Singleton . CustomMessagingManager . RegisterNamedMessageHandler ( m_Name , ReceiveMessageThroughNetwork ) ;
43
45
m_HasRegisteredHandler = true ;
You can’t perform that action at this time.
0 commit comments