Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

XrInputSource#elementEntity holds the ElementComponent, not the Entity its docs and type promise

Open Beginner friendly
#9,660 0 comments 0 reactions 0 assignees View on GitHub

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
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

area: xr

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

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 (their elementEntity.entity would become undefined), 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

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from playcanvas/engine

All issues in playcanvas/engine

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.