How do I make raycasting work with easyAR's camera?

I want to use the EventSystem to detect a click on a sprite child of ImageTarget. I add the Physics 2D raycaster to the RenderCamera(EasyAR_Startup->ARCamera->RenderCamera) and a BoxCollider 2D to the sprite. It doesn’t work. It works fine if I just use a normal camera(GameObject->Camera) on a non-AR experience though.

This is the component that I want to add to the sprite and make it work:

using UnityEngine;
using UnityEngine.EventSystems;

public class ClickAction : MonoBehaviour, IPointerClickHandler
{
    public void OnPointerClick(PointerEventData eventData)
    {
        Debug.Log("clicked");
    }
}

Note: I put the vuforia tag because I couldn’t find easyAR tag, and just thought that maybe vuforia users have the same problem and can help.

I tried to do the same and it doesn’t work for me either, but only if I use 2D physics.
The thing with 2D is that colliders are only drawn on the XY plane, so they aren’t affected by rotation, as you can see in this image:
129201-sprite.png
So the sprite can rotate as you want, but the collider won’t. This means that if the collider is perpendicular to the camera, it will appear as just a line, so it won’t work.

Instead, using 3D physics it works just fine.
I would advise you to do this:

  • Create a new material that uses the standard shader.
  • Set the rendering mode to Cutout and put your sprite into the Albedo field.
  • Put a quad or a plane in the scene and assing this material to it.
  • Put a 3D BoxCollider and your script on the new game object.
  • On the RenderCamera put a 3D Physics Raycaster, maybe with a Max Ray Intersection greater than 0 if you need it.

In my scene, it works.