Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Detecting if the current headset is Daydream or Cardboard?

Discussion in 'Daydream' started by stregillus, Jan 2, 2017.

  1. stregillus

    stregillus

    Joined:
    Oct 9, 2016
    Posts:
    10
    I'm trying to update my existing Cardboard game to have Daydream support, at least in having the Daydream controller act the same way as a "touch" event works with a normal Cardboard.

    My game involves holding down and releasing the input button on a Cardboard, and I don't see any actual way to detect whether or not the button is held down through the GoogleVR SDK. For Cardboard, I've just been using Input.GetMouseButton(0) to detect whether or not there's a touch event or not. This works fine for Cardboard.

    Because of the little nubs on the Daydream headset, that approach doesn't work in the Daydream headset, so I have to disable the code that does Input.GetMouseButton(0) for input if I'm in Daydream. Otherwise the game seems to think that I'm constantly holding down the button.

    However, I don't see any way or boolean value of "isDaydream" or something similar. Is there actually any way in Unity to get whether the viewer being used is Cardboard or Daydream? I am going crazy here, this should be something simple. UnityEngine.VR.VRSettings.loadedDeviceName ALWAYS returns the first item in the list in your Unity build settings. I tried checking the GvrController.State to to see if the daydream controller is connected, which seems to not work. I don't see any sort of "profile name" available in the GvrViewer class.

    My current solution is just to detect the Daydream controller button with GvrController, and if I detect the main button press I switch to "daydream mode". This works, but feels really clunky.
     
  2. joejo

    joejo

    Unity Technologies

    Joined:
    May 26, 2016
    Posts:
    958
    You need to check VRSettings.loadedDeviceName to see if the currently running device is "cardboard" or "daydream". That should let you know what device you are running on so you can make decisions about how to handle input.
     
  3. stregillus

    stregillus

    Joined:
    Oct 9, 2016
    Posts:
    10
    Like I mentioned, that does not work. loadedDeviceName will just show me whatever is the FIRST item in the "supported SDK" list. If Daydream is first, the string is always "daydream", even if I switch viewer in the Daydream app setting (and in the Cardboard app), force-quit the game, and then re-launch it. Same if Cardboard is first, it'll always show "cardboard" no matter what headset I have selected.
     
  4. thep3000

    thep3000

    Unity Technologies

    Joined:
    Aug 9, 2013
    Posts:
    400
    Arkade likes this.
  5. stregillus

    stregillus

    Joined:
    Oct 9, 2016
    Posts:
    10
    Wow, I knew that I was missing something simple and obvious! I will test this out later this afternoon.
     
  6. Jeff-Rosenberg

    Jeff-Rosenberg

    Joined:
    Oct 23, 2012
    Posts:
    26
    What about when a Daydream-compatible phone is running on a Cardboard headset? My S8 reports that loadedDeviceName is 'daydream' even though it's been set to run as Cardboard from the Daydream app. It launches and renders as a Cardboard app like normal. My S6 and S7 both report loadedDeviceName as 'cardboard' as you'd expect.

    Edit: I was able to somewhat resolve this by loading Cardboard before Daydream in Player Settings > XR Settings. This allows the app to properly launch when launched into Daydream on the Daydream app or into Cardboard on the Cardboard app. However, setting the viewer to Cardboard from the Daydream app and launching results in loadedDeviceName being 'daydream', which is incorrect. Launching the app manually attempts to load whatever viewer is set in the Daydream app, as you'd expect, but loadedDeviceName always reports as 'cardboard'.

    • Launched from Cardboard App + Set to Carboard Viewer = Launches as Cardboard, loadedDeviceName = 'cardboard'
    • Launched from Daydream App + Set to Daydream Viewer = Launches as Daydream, loadedDeviceName = 'daydream'
    • Launched from Daydream App + Set to Carboard Viewer = Launches as Cardboard, loadedDeviceName = 'daydream' (incorrect)
    • Launched from Home + Set to Carboard Viewer = Launches as Cardboard, loadedDeviceName = 'cardboard'
    • Launched from home + Set to Daydream Viewer = Launches as Daydream, loadedDeviceName = 'cardboard' (incorrect)
     
    Last edited: Dec 5, 2017
    tmendez, unnamed7 and Arkade like this.