WebXR HitTest: Failed to construct 'XRRay'

When providing a optional offsetRay to the hitTest.start method, playcanvas throws the following error:

xr-hit-test.js:239 Uncaught TypeError: Failed to construct 'XRRay': Direction's `w` component must be set to 0.0f!
    at XrHitTest.start (xr-hit-test.js:239:32)

HitTest is started as described in api documentation:

var self = this;

this.ray = new pc.Ray(new pc.Vec3(0, 0, 0), new pc.Vec3(0, -1, 0));
            spaceType: pc.XRSPACE_LOCAL,
            entityTypes: [pc.XRTRACKABLE_POINT, pc.XRTRACKABLE_PLANE],
            offsetRay: self.ray,
            callback: function (err, hitTestSource){...}

Can you provide an example project please with the issue?

Will provide today.

somehow the error does not show anymore, however, the overall behavior is still the same:


WebXR AR ‘immersive’ mode closes immediately after starting when custom ray is provided to hittest. Custom ray can be deactivated by the checkbox on the hitTest script on the root node.

I had a look at this and it looks like an exception is being thrown when start is called if you try to pass an offset to it:


It tries to create an instance of XRRay which doesn’t exist.

I will log a ticket for this in the engine

1 Like

Ticket: XRRay class doesn't exist and throws exception if offsetRay is used when starting WebXR AR · Issue #4371 · playcanvas/engine · GitHub

1 Like

Fixed in https://github.com/playcanvas/engine/pull/4372

I expect this to go out with engine version 1.54.2 if we do release a patch or 1.55.0

1 Like