Oculus Go - UI interaction with the controller

Hi guys,
I am casting a ray fro the controller and see if there’s an object in front of it and interact with it. I have used the following script for that:

using System.Collections;

using System.Collections.Generic;

using UnityEngine;



public class PlayerPointer : MonoBehaviour

{



//Returns whatever object is infront of the controller

private GameObject pointerOver;

[SerializeField]

//Is the object that is currently intractable

private PropBase selectedObject;

//Is the object currently stored in hand, ready to throw.

[SerializeField]

private PickUp inHand;



//This is a refrance to the object we want the pointer to be cast from.

[SerializeField]

public Transform controllerRef;

//This is where we want object we are holding to appear

[SerializeField]

private Transform holdingRef;

//The amount of force we want to throw objects from our hand with.

[SerializeField]

[Range(2, 50)]

private float throwForce = 30;



//The script that handles the visuals to show what object is selected

[SerializeField]

private HighlightObject selectVisual;

private LineRenderer line;



void Start()

{

line = GetComponent<LineRenderer>();

}



void Update()

{

//If a object is currently being held I don't want to select another object until it is thrown.

if (inHand == null)

{

WorldPointer();

}

else

{

line.SetPosition(0, controllerRef.position);

line.SetPosition(1, controllerRef.position);

pointerOver = null;

}

//This function handles how you intract with selected objects

Intract();

}



//This function handles shooting a raycast into the world from the controller to see what can be intracted with.

void WorldPointer()

{

//We set the line visual to start from the controller.

line.SetPosition(0, controllerRef.position);



RaycastHit hit;

//We reset the pointer so things don't stay selected when we are pointing at nothing.

pointerOver = null;



//This sends a line from the controller directly ahead of it, it returns true if it hits something. Using the RaycastHit we can then get information back.

if (Physics.Raycast(controllerRef.position, controllerRef.forward, out hit))

{

//Beacuse raycast is true only when it hits anything, we don't need to check if hit is null

//We set pointerOver to whatever object the raycast hit.

pointerOver = hit.collider.gameObject;

//We set the line visual to stop and the point the raycast hit the object.

line.SetPosition(1, hit.point);



//Here we check if the object we hit has the PropBase component, or a child class of its.

if (pointerOver.GetComponent<PropBase>())

{

//We set the object to be highlighted

selectVisual.NewObject(pointerOver);

}

else

{

selectVisual.ClearObject();

}

}

else

{

//If the raycast hits nothing we set the line visual to stop a little bit infrount of the controller.

line.SetPosition(1, controllerRef.position + controllerRef.forward * 10);

selectVisual.ClearObject();

}



Debug.DrawRay(controllerRef.position, controllerRef.forward * 10, Color.grey);

}



void Intract()

{

//We set up the input "OculusPrimaryIndexTrigger" in the Input manager

if (OVRInput.GetDown(OVRInput.Button.PrimaryIndexTrigger))

{

{

selectedObject.Trigger();

}

//If you have a object that you need to hold down a button to intract with

}

else if (pointerOver != null)

{

if (pointerOver.GetComponent<PropBase>())

{

selectedObject = pointerOver.GetComponent<PropBase>();

}

else

{

selectedObject = null;

}

}

else

{

selectedObject = null;

}



}



}

Now I created a UI interface,and in the canvas I added few buttons, which I want to interact with using this ray, however this ray just goes through them.
I have added the OVR Input Module script to the Event system and have replaced Graphic Raycaster with OVR ray caster in the canvas and has also changed the render mode to world space in the canvas.
However, i can still not interact with the UI buttons with this ray.
Can someone please help me with this issue! Any help will be greatly appreciated.

You’re on the right track. Something’s obviously missing, but what?

You say you added OVRInputModule to EventSystem. Did you also remove the previous input module? (You should.)

On the OVRRaycaster, you have to set the Pointer to the transform that defines the ray. Did you do that?

1 Like

Hey,
I did remove the previous input module, right now my event system has only event system and OVR Input Module scripts.
Also, I have set the Pointer to controllerRef, which as in the code shows is the object where the ray is being casted from and is a child to OVRPlayerController.

//This is a refrance to the object we want the pointer to be cast from.[SerializeField]

public Transform controllerRef;

However the ray still goes through the buttons.

Update: In Canvas>OVR Raycaster, I set Blocking Objects to All and Blocking Mask to everything.
In Event System> OVR Input Module, I changed Ray Transform from CenterEye Anchor to RightHandAnchor, which contained GoController s a child.
I also added OVRPhysicsRayCaster to OVRCAMERARIG, and set EventMask to everything and added box colliders to the button so that the ray collides with it.
It is working now, the ray stops when it collides with the button and also interacts with it when I press the button.
However, the only problem is that , now I see the gaze ring in the centre of the view every time and it can be moved by moving the ray from the controller along the floor. I tried deleting the gaze ring image from the asset, but then I see a white square instead of it.
Any suggestions?

2 Likes

I’m still looking for a way to do this easily without having to add colliders to the buttons. I can see in the debugger that my objects are hit. I just can’t easily access them. This should be super easy, is it really that rare of an ask?

It’s not “super easy” unless you use somebody else’s solution (such as CurvedUI, or something from the Oculus SDK samples). But it’s not all that hard if you understand the UI system. You do not need 3D colliders on your UI elements, though you will need one on the canvas.