Cannot read properties of null (reading 'x')

Sorry for my stupid question, I want to display coordinates of cursor in scene through GUI text but I don’t know why I am getting this error.

that’s because you are not hitting anything, so there is no hit-point. The second example has a ground, which I can only assume is pickable. so you get the coordinates of the hit point on this mesh.

If you want to display the coordinates of the cursor on the canvas you would be better off using pure HTML for that. Thought I am not 100% sure what you are trying to achieve :slight_smile:

1 Like

Of course if it didn’t hit anything “hit.pickedPoint” is null.
Interesting is that in playground it work, in may app I can log “hit.pickedPoint”-that return a Vector3, but when I go deeper “hit.pickedPoint.x” and “hit.pickedPoint.z” , that give the error "Cannot read proprieties of null

Not sure why it would work in PG and not in your app. Only thing is that when you log it, it’s already dirty.
May be you could try with “hit.pickedPoint._x”?

That was the problem, it didn’t hit anything.
But … at scene initialization when console log “hit.pickedPoint” despite it return “null” I can handle camera to pick ground mesh and then it works.
The problem was that when console log “hit.pickedPoint.x” it return “ERROR TypeError: Cannot read properties of null (reading ‘x’)” and I can not handle camera to “hit” any mesh. (I have also my own custom behavior of cammera).
I deduced that this would be the explanation. The most important thing is that I got what I wanted.
Thanks for the answers! :wink:

1 Like