Class ObserverBroadcastScope
Sends a broadcast to everyone observing a character except its owner.
public static class ObserverBroadcastScope
- Inheritance
-
ObserverBroadcastScope
- Inherited Members
Remarks
Every observer-facing message in this project has the same shape: the owner already knows, because it either predicted the change or received a reliable acknowledgement addressed to it, so sending it the observer copy costs bytes and is then discarded on arrival.
Why this exists rather than a direct BroadcastExcept call.
ServerManager.BroadcastExcept(HashSet, NetworkConnection, ...) calls
connections.Remove(excludedConnection) on the set it is handed. Passing
NetworkObject.Observers to it therefore does not exclude the owner for one message — it
permanently removes the owner from that object's observer set, and the owner stops receiving
every later observer message for its own character. The copy below is not an optimisation to
be removed; it is the thing that makes the call safe.
The scratch set is static and reused, which is safe because FishNet's server work is single-threaded and the set is fully consumed inside the call.
Methods
BroadcastToObserversExceptOwner<T>(NetworkObject, T, Channel)
Broadcasts message to networkObject's observers,
excluding its owner.
public static bool BroadcastToObserversExceptOwner<T>(NetworkObject networkObject, T message, Channel channel = Channel.Reliable) where T : struct, IBroadcast
Parameters
networkObjectNetworkObjectmessageTchannelChannel
Returns
- bool
True when the message was handed to at least one connection.
Type Parameters
T
Remarks
Silently does nothing when the object is not spawned or the server is not running: a caller that fires during startup or teardown has no observers to reach anyway, and the spawn payload is what carries state to anyone who arrives later.
CollectRecipients(IEnumerable<NetworkConnection>, NetworkConnection, HashSet<NetworkConnection>)
Copies observers into into, dropping
excluded and any null entries.
public static int CollectRecipients(IEnumerable<NetworkConnection> observers, NetworkConnection excluded, HashSet<NetworkConnection> into)
Parameters
observersIEnumerable<NetworkConnection>excludedNetworkConnectionintoHashSet<NetworkConnection>
Returns
- int
The number of recipients collected.
Remarks
Exposed for tests, which assert the owner is absent and that the source set is untouched.