question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Raycaster events not triggered on second render

See original GitHub issue

I just updated my A-Frame app’s aframe-react version from 3.5.0 to 4.2.4. I believe I have made all the changes required from the upgrade (events, vector properties, _ref), although the lack of a changelog makes it hard to say exactly.

I have everything working as it did before I updated aframe-react, except for one thing: I have a menu that can be toggled on and off. The menu is initially visible, and initially raycaster events such as click and mouseover work fine. However, when I toggle the menu off and on again the raycaster events are no longer triggered in 4.2.4. If I roll back to 3.5.0 - all other code and dependencies being equal - it works again.

I don’t toggle the visibility of the menu being setting the visible property. Instead I pass a prop to the React component rendering the menu telling it whether it should render or not. If the prop is true, the component returns an <Entity>, if it is false, it returns null. This setup is due to a number factors, related to how I use Redux to manage state and use of animations.

For performance reasons I have the configured the raycaster to only intersect with specific elements:

         <Entity
            primitive="a-cursor"
            raycaster='objects: .interactable'
          />

If I remove raycaster='objects: .interactable', the menu works every time, but I get worse performance.

I have reproduced the issue here: https://www.webpackbin.com/bins/-KkkMiVwnvG9MVsuq0us

The box toggles a sphere (a stand-in for the menu in my actual code). The first time the sphere is shown, it changes color when clicked. Once it has been hidden and is shown again, it no longer changes color.

From debugging, it seems like the Three.js raycaster simply doesn’t match the sphere on subsequent renders. I just can’t figure out how any of changes made in aframe-react affects this. It doesn’t seem to be related to the changes event system, since the problem is the same if I manually attach event handlers to the element. Rather, it seems like the intersected elements are somehow cached, or like the className is not properly included on subsequent renders.

But I have nothing solid, just this example reproducing the issue above. Any help would be appreciated.

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:16 (12 by maintainers)

github_iconTop GitHub Comments

1reaction
ipcommented, May 24, 2017

I think I found the problem, will send a pull request in a moment

0reactions
RSpacecommented, Jun 26, 2017

With the latest A-Frame master, filtering the raycaster using objects: .interactable works as expected for me, both for laser controls and cursor.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Three js raycast object mousedown event not triggered on ...
Hi i am try to catch click event for text-object in three js using raycast. ... // CLick event binding var mouse =...
Read more >
Raycaster not working or triggering properly - three.js forum
I've been going through the web to learn about raycaster, I have a glb model made in blender, I am using a “mousedown”...
Read more >
Problems with EventSystem when implementing a custom ...
Context: I'm rendering a 3D scene to a RenderTexture and showing it on a UI RawImage. In order to implement correct mousebehaviour, ...
Read more >
Line Renderer component - Unity - Manual
The Line Renderer component takes an array of two or more points in 3D space, ... Unity creates the point at the position...
Read more >
Unity's Event Components (Event Triggers, Physics ... - YouTube
In this video, I talk about Unity's Event Components like the Event Trigger, Physics 2D Raycaster, and the Physics Raycaster.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found