How can I get clicking and scrolling to work?

Symptoms

Cause

The main camera is missing a Physics Raycaster or the scene is missing an Event System with a compatible input module.

Resolution

By default, WebViewPrefab and CanvasWebViewPrefab respond to standard events from Unity's event system (like IPointerDownHandler, IScrollHandler, and IDragHandler), so they're compatible with input modules that dispatch those events, like Unity's Standalone Input Module and the input modules from the Oculus and Google VR SDKs.

A scene must include two things in order for clicking and scrolling to work:

  • The main camera must have a Physics Raycaster attached to it
  • The scene must include an Event System with an input module that dispatches the following events: IPointerDownHandler, IPointerUpHandler, IScrollHandler, and IDragHandler

3D WebView's demo scenes demonstrate this using Unity's Standalone Input Module, which works for desktop and mobile applications. For virtual and augmented reality, your VR or AR SDK usually includes an input module. For reference, please see the following webview example projects:

If an example project isn't listed for your VR or AR SDK, the following tips may be helpful:

  • Search your SDK for a demo scene that demonstrates clicking or selecting objects. If you locate a scene like that, you can try adding a Physics Raycaster to the main camera and adding a WebViewPrefab to it.
  • Search your SDK's documentation or files for the terms "input module" or "IPointerClickHandler" to locate information about its input module.

If your project or SDK implements its own proprietary event system that isn't compatible with Unity's event system, you can still enable clicking using one of the following approaches: