Class ObserverStreamingRegistry
Server-side scheduler that applies ObserverStreamingPolicy to every registered character: scales each one's observer range by local density, and for every viewing client ranks what it can see and rate limits everything beyond the cap.
public static class ObserverStreamingRegistry
- Inheritance
-
ObserverStreamingRegistry
- Inherited Members
Remarks
Characters register from CharacterPredictionController.OnStartServer — players,
monsters, pets, and the service NPCs built on the same prefab stack — because their
NetworkTransform and other per-tick traffic is what an observer's bandwidth is spent on.
Static classified objects (world items, waypoints) have no such hook and are adopted by
ObserverBudgetCondition on first evaluation, so that every classification can
be budgeted; they cost a position read per pass and nothing on the wire.
Runs one pass every RescheduleIntervalTicks ticks off FishNet.Managing.Timing.TimeManager.OnPostTick. A pass is O(entries) for density (uniform grid) plus, for ranking, each viewer against the objects in the grid cells within reach of it (the widest admitting range and the AI's declared proximity reach) and every wide-range object, with entries grouped by Unity scene so characters in different scenes never compare positions. Before the grid it was every viewer against every object: at 200 players and 700 characters, ~140k pair evaluations per half second.
Fields
MinimumHiddenTicks
Least time, in ticks, a character the byte budget took out of view stays out before the budget may let it back in: 3 s at 30 Hz. The mirror of MinimumVisibleTicks: at the budget's edge a crowd otherwise left and came back every few seconds, and each return was a full spawn. Never applies to a pinned character (party, target, a fight) or to one within the viewer's engagement range, which come back at once.
public static uint MinimumHiddenTicks
Field Value
MinimumVisibleTicks
Least time, in ticks, a character the budget let in stays in view before the budget may take it out again: 5 s at 30 Hz. A crowd wandering across the budget's edge otherwise spawned and despawned its members over and over, each time a full spawn (about 350 bytes) and an attribute snapshot (about 180) to the viewer for a few seconds of view.
public static uint MinimumVisibleTicks
Field Value
Properties
Count
Number of objects currently registered — characters and budgeted statics alike.
public static int Count { get; }
Property Value
LastPassBudgetExcluded
(viewer, observed) pairs excluded by the visibility budget in the last pass.
public static int LastPassBudgetExcluded { get; }
Property Value
LastPassByteEvicted
(viewer, observed) pairs the byte budget left out in the last pass.
public static int LastPassByteEvicted { get; }
Property Value
LastPassByteSlowed
(viewer, observed) pairs the byte budget slowed in the last pass.
public static int LastPassByteSlowed { get; }
Property Value
LastPassLimitedPairs
(viewer, observed) pairs rate limited in the last pass.
public static int LastPassLimitedPairs { get; }
Property Value
LastPassPinned
Characters pinned into a visibility budget in the last pass.
public static int LastPassPinned { get; }
Property Value
LastPassRangeChanges
Characters whose observer range was changed in the last pass.
public static int LastPassRangeChanges { get; }
Property Value
LastPassViewers
Viewers ranked in the last pass.
public static int LastPassViewers { get; }
Property Value
LongestPassMilliseconds
Longest scheduling pass since the last ResetLongestPass(), milliseconds (a diagnostic, never simulation).
public static double LongestPassMilliseconds { get; }
Property Value
Methods
Clear()
Drops every registration. For tests and server shutdown.
public static void Clear()
Remarks
Through Detach(ObserverStreamingEntry, int) rather than Unregister(NetworkObject), which takes the object and so cannot remove an entry whose object has already been destroyed — exactly the entries a shutdown is most likely to be holding.
Get(NetworkObject)
Returns the entry for a registered object, or null.
public static ObserverStreamingEntry Get(NetworkObject networkObject)
Parameters
networkObjectNetworkObject
Returns
IsViewerNearCombat(int)
True when the viewer's last pass found it near combat: a target it may harm, a fight it is part of, or a character in combat within its engagement range. Refreshed every pass (RescheduleIntervalTicks).
public static bool IsViewerNearCombat(int clientId)
Parameters
clientIdint
Returns
IsWithinVisibilityBudget(int, int, bool, out bool)
Whether a character is inside a viewer's visibility budget.
public static bool IsWithinVisibilityBudget(int viewerClientId, int observedObjectId, bool currentlyVisible, out bool hasRanking)
Parameters
viewerClientIdintClient id of the viewing connection.
observedObjectIdintObject id of the character being tested.
currentlyVisibleboolTrue when the viewer already observes it; widens the budget by the hysteresis.
hasRankingboolFalse when this viewer has no ranking yet.
Returns
- bool
True when the character is inside the budget.
Remarks
The budget condition's whole implementation. hasRanking distinguishes
"ranked and excluded" from "no pass has run for this viewer yet" — the caller must not
treat the second as a rejection, or everything stays hidden until the first pass lands.
LogSummary()
Logs a one-line summary of the last pass. For diagnostics.
public static void LogSummary()
Register(NetworkObject, ICharacter)
Registers a character. Installs the entry as the object's observer send filter.
public static ObserverStreamingEntry Register(NetworkObject networkObject, ICharacter character)
Parameters
networkObjectNetworkObjectcharacterICharacter
Returns
RegisterObject(NetworkObject)
Registers a classified object that nothing else registered — a dropped item, a waypoint.
public static ObserverStreamingEntry RegisterObject(NetworkObject networkObject)
Parameters
networkObjectNetworkObjectThe object to track.
Returns
- ObserverStreamingEntry
The entry, or null when the object is not classified.
Remarks
These have no CharacterPredictionController to register them from, so the call
comes from ObserverBudgetCondition the first time the object is evaluated:
that condition runs on the server for every object carrying the manager's defaults, and
it already holds the NetworkObject. The first evaluation defers (the object is
unranked, which is admitted) and the next scheduling pass ranks it — the same deferral a
freshly connected viewer gets, and the reason neither shows as a pop-in.
Only objects that declare a ClassifiedDistanceCondition are taken. Anything else has no budget to be measured against, and registering it would cost a per-pass position read for a decision that would always be "admit".
RequireViewerProximity(float)
Declares the farthest nearest-player distance a reader of TryGetNearestViewerDistance(NetworkObject, out float) compares against (squared, as the AI's LOD bands are authored). Within the largest one declared, the measurement is exactly the distance to the nearest player; beyond it, it is some distance beyond it (possibly NoViewerDistance), which every such comparison reads the same way.
public static void RequireViewerProximity(float sqrDistance)
Parameters
sqrDistancefloatSquared distance, metres². Infinity or NaN keeps every distance exact.
Remarks
Each viewer only measures the objects within this reach (and its ranking ranges) instead of every object in the scene. Until anything declares a reach the measurement is exact at every distance, as it always was.
The reach only grows: a reader must declare before the object it reads is first measured (an asset's load is early enough), and nothing can take reach away from a reader that already declared.
ResetLongestPass()
Starts a new measurement of LongestPassMilliseconds.
public static void ResetLongestPass()
RunPass()
Runs one scheduling pass over every registered character. Public so a server can force a pass after a bulk change (a load boundary) and so tests can drive it.
public static void RunPass()
TryGetNearestViewerDistance(NetworkObject, out float)
Distance from networkObject to the nearest player in its scene, as
measured by the last scheduling pass.
public static bool TryGetNearestViewerDistance(NetworkObject networkObject, out float distance)
Parameters
networkObjectNetworkObjectThe object to measure from.
distancefloatDistance to the nearest player, or
PositiveInfinitywhen the scene holds none.
Returns
- bool
True when a pass has measured this object.
Remarks
The proximity primitive server-side simulation should ask, in place of
NetworkObject.Observers. Observer membership answers "who is this object being
streamed to", which the visibility budget bounds — a monster outside every viewer's budget
has no observers and is still standing in a crowd. This answers "how close is the nearest
player", which is what a leash, a wake-up or an aggro sweep actually wants to know.
False when the object is not registered, or when no pass has measured it yet. Callers must
not read that as "nobody is near": it is an unanswered question, and the answer arrives
within one RescheduleIntervalTicks.
Unregister(NetworkObject)
Unregisters a character, restoring its prefab range and removing the send filter.
public static void Unregister(NetworkObject networkObject)
Parameters
networkObjectNetworkObject