Fix for missing Gizmos Menu items for projects that have ProBuilder installed #392
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.
Purpose of this PR
This PR fixes an issue where some Gizmos Menu items would be missing in projects that have the ProBuilder package installed.
Links
Fogbugz: https://fogbugz.unity3d.com/f/cases/1332226
Comments to Reviewers
Sequence of events causing this issue:
GizmoSetup(C++) receivesOnBeforeDomainReloadand clears all gizmo renderers and setupsAnnotationManager(C++) receivesOnDomainReloadand sets its dirty flag[InitializeOnLoad]attributes are processed and PBHierarchyListener's constructor is called which in turn callsAnnotationUtility.GetAnnotations()AnnotationManager.GetAnotations()internally callsAnnotationManager.Refresh()which, due to the dirty flag being set previously, attempts to rebuild annotations from an emptyGizmoSetupand clears the dirty flagOnDidReloadDomaintriggers,GizmoSetuprebuilds gizmo renderers and setupsAnnotationManager.Refresh()(C++) is called but it early exits due to the previously cleared dirty flag. This is whenAnnotationManagerwould normally rebuild annotations but, due toHierarchyListenerforcing an earlyAnnotationManager.Refresh(), the dirty flag has the wrong state.Proposed fix:
Delay
HierarchyListener's call toAnnotationUtility.GetAnnotations()by registering forAssemblyReloadEvents.afterAssemblyReloadcallback duringHierarchyListener's initialization. UsingEditorApplication.delayCalldelays it further and ensures there's no race condition betweenHierarchyListenerandGizmoSetup's handling ofOnDidReloadDomain.Tested opening existing projects that contain PB and adding/removing PB in open projects with 2019.4, 2020.3 and 2021.2.012a