Give us as much detail as possible regarding the issue you're experiencing.
Unity Editor version: 2022.3.6f1
ML2 OS version:1.4.0-dev1
MLSDK version: 1.4.0-dev1
Host OS: (Windows/MacOS): Windows
I'm trying to do a raycast of the eye gaze to gameobjects in the scene. For 3D objects, the following code works well:
var leftEyePosition = eyes.leftEyePosition;
var leftEyeRotation = eyes.leftEyeRotation;
var leftEyeGazeDirection = leftEyeRotation * Vector3.forward;
var leftEyeRay = new Ray(leftEyePosition, leftEyeGazeDirection);
if (Physics.Raycast(leftEyeRay, out RaycastHit leftEyeRaycastHit, 100))
{
// hit something
var hitPoint = leftEyeRaycastHit.point;
var _rayLength = leftEyeRaycastHit.distance;
var gameObject = leftEyeRaycastHit.collider.gameObject;
}
I could find the gameobject just fine. But when it comes to 2D UI objects, I could not find any game object. I'm using canvas -- see the figure below for my UI structure:
As some posts pointed out, I added a mesh collider
to my UI objects and it didn't work. I tried adding mesh renderer
and setting Cull Transparent Mesh
in Canvas Render
to false (not sure if it's helpful) but still cannot raycast to it. I tried to look at the examples but seems that none of them uses Canvas -- Is it bad practice to use Canvas for ML2 development? Is so, what should I do and is there a general guideline for it? If I could still use Canvas, is there a way for me to hit these UIs? This post said something about casting ray to 2D UIs, but I don't think a similar EventSystem
exists here.
Any help would be appreciated. Thanks in advance!