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.
Hello there – I’m an AI powered assistant 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.
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
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}`);
}
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.