Raycasting error

Hello Needle,

I’m working on the front-end part of my needle project, I have access only to the web repo (not the unity one).
I’m working on another computer than habitual. And I got a strange bug with the raycasting.
Version 3.27.3-pre

Now, when I launch a raycasting like it for example :

onPointerClick() {
    const ray = this.context.physics.raycast();

    console.log(ray)
}

The ray is always empty:
How can I debug that ? My ObjectRaycaster is added automatically to my scene on start.

Thanks for your help,

Original Post on Discord

by user 224464722878005248

Hello there – I’m an AI powered assistant :robot: that might be able to help you with your question. Would you like me to try helping you?

How it works:
Reply to the messages of the bot that end with a thread_id to interact with it and ask follow-up questions. You can also mention the bot directly in this channel to get help.

Help requested: please wait a moment…

Here is what I found for you :brain: Discord

It tested if the scene and the camera is the same in this.context.physics and it is
And my onPointerMove, click, up and down works so I don’t know what’s going on

by user 224464722878005248

  • my raycasting from rapier work :confused:

by user 224464722878005248

Hello AeistDesmos,

When dealing with issues related to raycasting, consider the following steps to debug:

  1. Verify that there are indeed objects in the scene that can be intersected by the ray.
  2. Ensure that the ObjectRaycaster is properly added and enabled in the scene.
  3. Check whether the collider components on the objects are correctly set up to interact with raycasting.
  4. Confirm that the camera is correctly set up and that the ray is being cast in the correct direction.

Here’s some pseudocode to help you debug:

  • Log the scene objects to ensure there are objects that can be intersected.
  • Check if ObjectRaycaster is present and enabled.
  • Log collider details of the game objects expected to be hit by the ray.
  • Verify the mainCamera is correctly set up and use it for raycasting.
*thread_uOlyvcHjR43JjAZSVXv0ELVP*

typescript
onPointerClick() {
// Ensure there are objects that the ray can intersect with.
console.log(this.context.scene.children);

// Confirm that ObjectRaycaster is present and enabled.
const raycaster = this.gameObject.getComponentInParent(ObjectRaycaster);
if(!raycaster){
    console.error('ObjectRaycaster is missing');
    this.gameObject.getOrAddComponent(ObjectRaycaster);
    return;
}
if(!raycaster.enabled){
    console.error('ObjectRaycaster is not enabled');
    return;
}

// Perform the raycast using the main camera.
const camera = this.context.mainCameraComponent;
if (!camera) {
    console.error('Main camera component is missing');
    return;
}
const ray = this.context.physics.raycast({ camera: camera.camera });

// Log the raycast result.
console.log(ray);

// If ray is still empty, log details of a specific object's collider as an example.
const specificObject = this.context.scene.getObjectByName("YourObjectWithColliderName");
if(specificObject) {
    const collider = specificObject.getComponent(Collider);
    console.log(`Collider details: ${collider}`);
}

}

*thread_uOlyvcHjR43JjAZSVXv0ELVP*

If you follow this pseudocode, replace “YourObjectWithColliderName” with the actual name of one of your objects that should be hit by the ray. If it turns out that the colliders are not set up correctly or are disabled, you should look into enabling them or adjusting their settings. If the issue remains unresolved, please let me know for further assistance.

1 messages left GPT 4
thread_uOlyvcHjR43JjAZSVXv0ELVP

by user 224464722878005248

Is this normal ?

by user 224464722878005248

I will try to reinstall my node_modules and deleting my package-lock.json

by user 224464722878005248

Ok it was this, sorry for bothering you

by user 224464722878005248

So reinstalling fixed the issue? Thanks for the update

Yes, the package-lock.json has blocked the update of the node-modules so the raycasting was not updated correctly and it created this error

by user 224464722878005248

So if you got the same error, delete node-modules and package-lock.json and npm install

by user 224464722878005248