Skip to content
Create a gist now

Instantly share code, notes, and snippets.

Lets you use a VR world space cursor with World Space Canvases in Unity3D 4.6. Add this to the EventSystem object. Put some box colliders on your buttons in the World Space Canvas. Then, do a trace to see if you're looking at a menu object--if the trace hits one of those buttons, pass it to SetTargetObject. See for a longer e…
using UnityEngine;
using UnityEngine.EventSystems;
//by Ralph Barbagallo
public class VRInputModule : BaseInputModule {
public static GameObject targetObject;
static VRInputModule _singleton;
void Awake() {
_singleton = this;
public override void Process()
if (targetObject == null)
if ( { //I poll my own inputmanager class to see if the select button has been pressed
//We tapped the select button so SUBMIT (not select).
BaseEventData data = GetBaseEventData();
data.selectedObject = targetObject;
ExecuteEvents.Execute(targetObject, data, ExecuteEvents.submitHandler);
public override bool IsPointerOverEventSystemObject (int pointerId)
if (targetObject != null)
return true;
return false;
public static void SetTargetObject(GameObject obj) {
//we're hovering over a new object, so unhover the current one
if ((targetObject != null) && (targetObject != obj)) {
PointerEventData pEvent = new PointerEventData(_singleton.eventSystem);
pEvent.worldPosition = FlarbCrosshair3D.GetRaycastStart();
ExecuteEvents.Execute(targetObject, pEvent, ExecuteEvents.pointerExitHandler);
if (obj != null) {
//this is the same object that was hovered last time, so bail
if (obj == targetObject)
//we've entered a new GUI object, so excute that event to highlight it
PointerEventData pEvent = new PointerEventData(_singleton.eventSystem);
pEvent.pointerEnter = obj;
pEvent.worldPosition = FlarbCrosshair3D.GetRaycastStart();
ExecuteEvents.Execute(obj, pEvent, ExecuteEvents.pointerEnterHandler);
targetObject = obj;

Hi Ralph
Thanks for supplying this code.
Can you put the code for your InputManager or a complete demo scene here as well?
Also, what is FlarbCrosshair3D? I am guessing it is a singleton of you custom cursor.



This was the kind of code I was looking for, however I am getting an override error. As LumenDigital stated, could you post a InputManage Demo? It would be very helpful.


grobm, if you take a look at the Base class it is inheriting from then it looks like the method name has changed to public virtual bool IsPointerOverGameObject(int pointerId);


Yeah could you please post the code for your InputManager please :)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.