Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No event when Canvas Render Mode is set to World Space

I am building an AR iOS app that uses ARToolkit for Unity3D. My goal is to create a UI in World Space mode so that when I point the phone camera to an image, it will show the UI in 3D (e.g. select products or scroll through information list, etc...).

Instructions I followed:

https://github.com/artoolkit/ar6unity-wiki/wiki/Setting-Up-Your-First-ARToolKit-for-Unity-Scene

https://github.com/artoolkit/ar6unity-wiki/wiki/ARToolKit-for-Unity-on-iOS

I have no problem making UI Render Mode = Screen Space Overlay. That means the UI canvas is "fixed" on the screen regardless of camera movement. However, when I use World Space, the UI touch input events just don't trigger. Here is the setting for my project:

Marker2 is where the image detection happens. Then it should show 2 cubes and 1 UI canvas with button and scroll view (outside of this screenshot - don't matter regarding this)

enter image description here

This is my canvas properties. Note that I put it in Default layer so the UI will show and Render Mode = World Space:

enter image description here

OK, I held up my image and it detects and shows 2 cubes and the button. But any click or touch on the button has no effect. Previously in UI Layer and Screen Space Overlay, I can hit the button and it works fine (basically output some text in Console - doesn't matter).

enter image description here

Anyways I tried to test with a new project where I don't use ARToolkit but just a regular Camera. Everything works fine. So it definitely has something to do with ARToolkit interrupting the mobile touch events.

Please help and point me some direction on why mobile touch input doesn't work in ARToolkit using UI World Space.

like image 720
HP. Avatar asked Dec 10 '22 10:12

HP.


1 Answers

This is really some trick stuff in unity.

You have to understand the following:

  • If you change the Canvas to World Space, Canvas will look for a camera with the tag "MainCamera" and use it as the camera to perform the raycast.

    enter image description here

  • If the Camera with the "MainCamera" tag is not found, Unity will use the Camera that set in the Canvas' Event Camera slot.

    enter image description here

  • Finally, if the Camera with the "MainCamera" tag is not found, and there is no camera set in the Canvas' Event Camera slot, there will be no raycast and your UI will not send any event.

So you either have to change the Camera's tag to "MainCamera" or plug the main camera to the Event Camera slot in the Canvas or perform both actions if his is not working with the artoolkit. From the screenshot you posted, that slot is not assigned because it says "None".

like image 113
Programmer Avatar answered Dec 13 '22 03:12

Programmer