TL;DR

After upgrading from Google VR to Google Cardboard XR Plugin. Looking for documentation/advice on:

  1. How to use the Event Trigger component in the editor rather than code
  2. How to limit the distance that a user can interact with an object via the reticle pointer

Background:

  1. I built my app using v2019 of the Unity Editor. However I can't compile for Android APK 31 which is needed to publish on Google Play. I have been told this is because I need to use a later version of the Editor
  2. When I upgrade to v2020+, I get errors around my VR implementation using Google VR mainly around Daydream
  3. I have been told that I need to migrate to the new Google Cardboard XR Plugin to resolve this, which I have now done
  4. When I follow the installation guide for Google Cardboard XR Plugin, the set up appears to use a different way of interacting compared to how I have implemented
  5. By design I only use gaze and choose; no buttons, no controllers - this is mandatory moving forward
  6. I can make this work by using public void OnPointerEnter() and public void OnPointerExit() in my code
  7. With hundreds of active objects I would really rather not have to rewrite all my scripts and remove the event triggers from the editor view
  8. It is vital that I can control the distance from the camera that an object is "interactive" to avoid unintentional interactions with objects in the distance/out of view

My current approach:

a. I set the distance of the reticle pointer

b. attach a collider to the object i want to make active and make this a trigger

c. add event triggers to the object. I use the pointerEnter and pointerExit event triggers

Editor view of setup for working with interactive objects

If the object is within range of the camera/reticle pointer, then it becomes active and my script runs. This generally first checks that the user remains focused on the object for e.g. 1-3 seconds (determined by my script), then action the rest of the script - this ensures that the object isn't selected by mistake. This works perfectly for my needs and is implemented consistently across my app

Result:

When I try to run this with the new plugin in my app, following the quick setup guide, I do get the expected behaviour; the reticle pointer changes state from a dot to a circle but I then get the following errors:

When I "look" at the interactive object

Failed to call function OnPointerEnter of class EventTrigger Calling function OnPointerEnter with no parameters but the function requires 1. UnityEngine.GameObject:SendMessage (string) CardboardReticlePointer:Update () (at ./Library/PackageCache/com.google.xr.cardboard@17e19f289a/Runtime/CardboardReticlePointer.cs:158) Failed to call function OnPointerExit of class EventTrigger

When I "look away" from the interactive object

Calling function OnPointerExit with no parameters but the function requires 1. UnityEngine.GameObject:SendMessage (string) CardboardReticlePointer:Update () (at ./Library/PackageCache/com.google.xr.cardboard@17e19f289a/Runtime/CardboardReticlePointer.cs:167)

I did find this post but don't know if it is relevant since I don't understand the solution and definitely don't feel comfortable changing Google code without a bit of hand holding

Error says function requires 1 parameter when it actually requires none

https://forum.unity.com/threads/calling-function-pickup-with-no-parameters-but-the-function-requires-1.702509/

So please can you help with the following:

How do i implement reticle pointer + collider + onPointerEnter/onPointerExit event handlers in the Editor (not code) to execute the script assigned to that object without having to change hundreds of objects to a different approach?

Given it works when I replace the Event Triggers in the Editor with code, I think I just need to know:

  1. How to use the Event Trigger component in the editor rather than code
  2. How to limit the distance that a user can interact with an object

Please let me know if anything isn't clear or you need more information

thanks

1

There are 1 best solutions below

0
On

The Reticle included in the HelloCardboard demo scene is sending "OnPointerEnter", and "OnPointerExit" messages to the objects in the UI layer the ray hits, which the EventTrigger doesn't respond to.

You can write your own super simple MessageTrigger class to respond to those messages sent form the reticle, and use that instead of the EventTrigger component. That is a C# script with these two methods: public void OnPointerEnter(), and public void OnPointerExit().

Or you could use a PhysicsRaycaster, and extend the Event System Input to make the reticle work with the standard EventTrigger.

Descriptions can be found for example in this Cardboard SDK forum thread: https://github.com/googlevr/cardboard/issues/140