Repository navigation
Invoke OnObserversActive when the last observer is removed - #1086
Open
jimdroberts wants to merge 1 commit into
Open
jimdroberts wants to merge 1 commit into
jimdroberts wants to merge 1 commit into
Conversation
RemoveObserver invoked ObserversActiveChanged when removed && startCount == 0, which can never be true. Use startCount == 1, the last-observer edge, as TryInvokeOnObserversActive did before 4.7.0.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
NetworkObject.OnObserversActiveis documented as "Called when this NetworkObject losses all observers or gains observers while previously having none." Since 4.7.0 it does not fire when the last observer is removed throughRemoveObserver, for example when a client leaves range, changes scene or disconnects. It still fires on gain and onClearObservers. The internalObserversActiveChanged_LevelOfDetailhook is skipped in the same case. Code that pauses work for unobserved objects on this event never gets the "now unobserved" edge.Cause
Runtime/Object/NetworkObject/NetworkObject.Observers.csL256-264 on main:If
removedis true,startCountwas at least 1, so the condition can never be true. In 4.7.0R (6d1754c)TryInvokeOnObserversActive(startCount)was replaced by this inline check. The old helper fired onObservers.Count == 0 && startCount > 0. The add path (L236,startCount == 0) andClearObservers(L221,startCount > 0) were converted correctly.Fix
startCount == 0→startCount == 1. This is the "lost the last observer" edge. Becauseremovedis true, it is equivalent to the pre-4.7.0Observers.Count == 0 && startCount > 0.Behavior change
OnObserversActive(and the level-of-detail hook) now fire when an object's last observer is removed viaRemoveObserver. This is the documented behavior, and the behavior before 4.7.0.