XrInputSource#elementEntity holds the ElementComponent, not the Entity its docs and type promise
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 75/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- javascript, typescript
- Domain
- api
Research direction
Start from the elementEntity getter in src/framework/xr/xr-input-source.js (~L439-447) and the assignment in src/framework/input/element-input.js (~L859), tracing element back through _getTargetElementByRay (~L512-516). Decide whether to store element.entity (matches the name, docs, type and manual; needs a release note) or update the JSDoc and generated playcanvas.d.ts to ElementComponent. Pin the choice with a test that points an input ray at an element using the null device and test/framework/xr/fake-webxr.mjs.
Written by the indexing model from the issue text.
Description
XrInputSource#elementEntity is documented as the "entity with Element component at which this input source is hovering" and typed Entity|null, but ElementInput stores the hovered ElementComponent in it. Code that follows the docs or the TypeScript type breaks at runtime: elementEntity.name is undefined and elementEntity.getPosition() throws. Only a null check works either way.
Where
- The docs and type: https://github.com/playcanvas/engine/blob/6767f256721572a34f37daba419c18da8566f5ab/src/framework/xr/xr-input-source.js#L439-L447, emitted as
get elementEntity(): Entity | nullin playcanvas.d.ts - The assignment: https://github.com/playcanvas/engine/blob/6767f256721572a34f37daba419c18da8566f5ab/src/framework/input/element-input.js#L859.
elementcomes from_getTargetElementByRay, which returns one of theElementComponents registered withaddElement(https://github.com/playcanvas/engine/blob/6767f256721572a34f37daba419c18da8566f5ab/src/framework/input/element-input.js#L512-L516).
Both date from #1988 (2020), which documented the property as a pc.Entity.
Repro
On the null device, with the fake WebXR session from test/framework/xr/fake-webxr.mjs, I set up a world-space screen with one useInput image element (button), an ElementInput, and a controller whose ray points at the element. After one XR frame:
| Check | Result |
|---|---|
inputSource.elementEntity instanceof Entity |
false |
inputSource.elementEntity === button.element |
true |
inputSource.elementEntity.entity === button |
true |
inputSource.elementEntity.name |
undefined |
inputSource.elementEntity.getPosition() |
TypeError: ... getPosition is not a function |
In a browser, any XR session with world-space UI shows the same:
app.xr.input.on('selectstart', (inputSource) => {
console.log(inputSource.elementEntity); // an ElementComponent while over UI
});
Nothing in the engine, its examples or scripts/esm reads the property. The user manual repeats the documented contract on UI in XR ("The entity of the element that this input source points at") and Input Sources ("read its elementEntity for the entity of the element it points at").
Fix
There are two options:
- Store
element.entity, which matches the name, the docs, the type and the manual. This changes the value for anyone relying on the component today (theirelementEntity.entitywould becomeundefined), so it needs a release note. - Keep the value and change the docs and type to
ElementComponent|null. The name would stay misleading, and the manual would need updating.
A test that points an input source's ray at an element and checks elementEntity would pin either choice.
Found in passing while auditing the XR scripts in scripts/esm/xr.
- Dominant language
- JavaScript
- Stars
- 17k
- Forks
- 2k
- Avg merge
- 4h 21m
- Merged PRs (30d)
- 286
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing 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.
More from playcanvas/engine
-
Difficulty 2/5 1-3 hours Newbie friendliness 80/100
playcanvas/engine#9769 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
playcanvas/engine#9767 ·
Maintainers usually reply within 1 day
-
Isotropic GGX specular visibility term uses alpha^4 instead of alpha^2Possibly taken @Yahiro025 claimed this 25 days ago. Openarea: gltf area: graphics
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
playcanvas/engine#9510 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
playcanvas/engine#9335 ·
Maintainers usually reply within 1 day
-
area: ui enhancement
Difficulty 1/5 Under an hour Newbie friendliness 72/100
playcanvas/engine#5777 ·
Maintainers usually reply within 1 day
All issues in playcanvas/engine
Similar issues
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Billionmail/BillionMail#389 ·
-
beginner-friendly category:finding-titles community enhancement first-timers-only good first issue hacktoberfest help wanted low hanging fruit micro-contribution type: task up-for-grabs
Difficulty 1/5 1-3 hours Newbie friendliness 85/100
Berserk-hub150/skillhawk#227 · 1 comment ·
Maintainers usually reply within 8 days
-
Remove responsibilities not working in Custom Roles & BadgesPossibly taken @thomasgwatson claimed this today. Openagent-ready agent:needs-test
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
Maintainers usually reply within 2 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
gkjohnson/three-mesh-bvh#933 ·
-
scope: curriculum status: waiting triage
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
freeCodeCamp/freeCodeCamp#71076 ·
Maintainers usually reply within 1 day