scene manipulations during event callbacks
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 17.6k
- Forks
- 4.4k
- PR merge metrics
- No merged PRs in 30d
Description
In my ar-scene setup, I want to replace the default camera entity with my own "ar-camera" entity, if the user did not create one in the scene.
So, in the scene's "loaded" callback (play method, actually), I grab a list of cameras, and look for an "ar-camera" entity. This is all good.
BUT, I also want to disable any camera that is already there by setting active=false.
The problem is that the camera system ALSO has a "loaded" callback, in which it creates a default camera (if there isn't one) and attaches it to the scene.
Unfortunately, the a-node attachedCallback does not seem to run for these new nodes until after all of the various "loaded" handlers are run. Which means that this.sceneEl in these nodes is not set, so when I call cameraEl.setAttribute('camera', 'active', false); on the default camera that the camera system created, it throws an error inside the camera's init method (since setAttribute calls updateComponent which calls init on the uninitialized component (in a-entity.js).
It seems that there needs to be something in there to check (during init, I guess?) it's it's attached BUT the attached callback hasn't been called? If so, do the same work (like setting the sceneEl)?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing the scene and camera systems' loaded callbacks, the play method, and a-node's attachedCallback. Read a-entity.js around sceneEl assignment, updateComponent, and camera init to reproduce the failure when the default camera is created and immediately modified. Done means camera changes during loaded callbacks no longer invoke an uninitialized component and the created node has the expected scene context.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- ar-vr-xr
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100