fix: improve XrControllers script robustness and documentation#8410
Merged
Conversation
- Fix race condition when input source is removed during async profile loading - Add XR session end cleanup to destroy all controller entities - Add proper destroy lifecycle with event listener cleanup - Change profile loading from parallel to sequential (stop on first success) - Add comprehensive JSDoc documentation and type imports - Add visibility control (visible property) for controller models - Fire xr:controller:add and xr:controller:remove events for coordination - Add getControllerEntity() helper method - Clean up loaded assets when controllers are removed
Contributor
There was a problem hiding this comment.
Pull request overview
This PR hardens the XrControllers script to be more robust around XR input lifecycle, cleans up resources correctly, and documents its behavior and API for easier integration with other XR scripts.
Changes:
- Refactors controller lifecycle management: adds
_pendingInputSourcesto avoid races during async profile loading, centralizes session-end and destroy cleanup, and introduces_onInputSourceAdd/_onInputSourceRemove/_onXrEndhelpers. - Switches profile loading from parallel to sequential (first-success wins), adds controller visibility control (
visiblegetter/setter) and agetControllerEntity()helper, and starts firingxr:controller:add/xr:controller:removeevents. - Adds comprehensive JSDoc annotations and type imports to align with other XR-related scripts.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
willeastcott
added a commit
that referenced
this pull request
Jan 26, 2026
* fix: improve XrControllers script robustness and documentation - Fix race condition when input source is removed during async profile loading - Add XR session end cleanup to destroy all controller entities - Add proper destroy lifecycle with event listener cleanup - Change profile loading from parallel to sequential (stop on first success) - Add comprehensive JSDoc documentation and type imports - Add visibility control (visible property) for controller models - Fire xr:controller:add and xr:controller:remove events for coordination - Add getControllerEntity() helper method - Clean up loaded assets when controllers are removed * refactor: remove redundant getControllerEntity helper method * refactor: centralize controller cleanup to prevent asset leaks * refactor: use recursive helper to avoid await-in-loop lint error
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.
Summary
visibleproperty) for controller modelsxr:controller:addandxr:controller:removeevents for coordinationTechnical Details
Bug Fixes:
_pendingInputSourcesSet to track input sources during async loading. Checks validity after each async operation and cleans up resources if removed.app.xr.on('end', ...)that destroys all controller entities when the XR session ends._onDestroy()method usingonce('destroy', ...)pattern for proper event listener cleanup.Promise.all()to sequential loop that stops on first successful profile match.Enhancements:
visiblegetter/setter for showing/hiding controller modelsTest plan