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

Issue with UI not showing in correct position

Discussion in 'VR' started by CrazyTegger, Jun 7, 2016.

Thread Status:
Not open for further replies.
  1. CrazyTegger

    CrazyTegger

    Joined:
    Feb 15, 2015
    Posts:
    57
  2. Unity_Wesley

    Unity_Wesley

    Unity Technologies

    Joined:
    Sep 17, 2015
    Posts:
    558
    Hello,

    Hopefully this forum post will help you set up your UI, also usually the measurement is in meters not pixels.

    Here is a Forum post to help set up UI.
    http://forum.unity3d.com/threads/unity-ui-on-the-hololens.394629/

    Following the steps under "Required configuration" will allow Unity UI to continue to work in the editor, but it'll also work in the HoloLens using tap and navigation gestures.

    Required configuration:
    • If you don't have any UI objects yet, create one (GameObject -> UI -> Button/Toggle/Slider/etc.)
    • Select the EventSystem object (this GameObject is automatically created for you when you create an UI objects, but unlike other UI objects, does not have Canvas as a parent/ancestor)
    • Add the "HoloLens Input Module" component to EventSystem (leave StandaloneInputModule attached for the UI to still work in the editor with mouse and keyboard)
    • Select the Canvas object (this containing GameObject is automatically created for you, and is a parent/ancestor to your UI objects)
    • Change "Render Mode" to "World Space"
    • Drag the Main Camera object onto the "Event Camera" field
    • Remember to put your camera's position at the origin
    Recommended steps to get started with a more useable UI:
    • In the Canvas Scaler component of the Canvas object, change "Dynamic Pixels Per Unit" to 10 - this will remove a lot of text aliasing without shrinking the text size too much
    • At the bottom of the Rect Transform of the Canvas object, change the Scale in both X and Y to somewhere around 1/16 (0.0625) to 1/32 (0.03125) or so to make the size of UI objects more manageable (use the same value for X and Y to avoid non-uniform scaling, of course).
    • Set the Canvas position to 0 for X and Y, and a distance of 3-5 or so along Z (this will make it so that your UI is immediately visible after the splash screen goes away)
    • For sense of scale, create a button, masked background, or some other visible UI object and set its width and height to 100 by 100. Make sure you can see this in the Game window, and deploy to the HoloLens as usual. This should give you a better idea of how you'll want to size and position your UI.
    • Create a cursor to more easily tell where your gaze is pointed at (you can use the HoloToolkit to do this pretty painlessly). Especially if you choose not to create a cursor, it's highly recommended that you make the colors, animations, etc., for different states of your UI objects (Normal/Highlighted/Pressed/Disabled) very noticeably different - during initial development, at least - to make it more obvious what you're looking at and whether the gesture was done and interpreted correctly.
    Run-time use:
    • Tap gestures of a gazed-at object will act as a quick single-click at that position. The "Time To Press On Tap" field of the HoloLens Input Module component controls the number of seconds that such taps will leave the UI object in the tapped state for better user feedback.
    • Use navigation gestures where click and drag would normally be needed, such as when moving a slider or scroll bar. The "Normalized Navigation To Screen Offset Scalar" field of HoloLensInputModule defines the number of pixels of emulated mouse movement when a value of positive or negative 1 is reported by the device for a navigation gesture.
    Known issues:
    • During a navigation gesture interacting with a Slider object, said object's appearance will change between Highlighted and Pressed. The navigation gesture will still work fine during this apparent state-flickering, however, so aside from altered appearance, it should still behave correctly.
     
  3. CrazyTegger

    CrazyTegger

    Joined:
    Feb 15, 2015
    Posts:
    57
    Thanks - I don't see an option for 'Dynamic Pixels Per Unit' in the scaler. Could it be called something else?
     
  4. Unity_Wesley

    Unity_Wesley

    Unity Technologies

    Joined:
    Sep 17, 2015
    Posts:
    558
    Hello,

    Here is a screen of the canvas set to world space for the render mode.

    Hope it helps.

    upload_2016-6-7_11-10-36.png

    Thank you,
    Wesley
     
  5. CrazyTegger

    CrazyTegger

    Joined:
    Feb 15, 2015
    Posts:
    57
    So how do you get this to work by using screen space - camera instead of world space camera. I don't want my UI to be stuck in a single location.
     
    Last edited: Jun 8, 2016
  6. razielanarki

    razielanarki

    Joined:
    Jun 1, 2014
    Posts:
    58
    i've noticed something similar:

    when i try to use a "screen space camera" ui on the main camera with a different plane than 1.0 the ui seems displaced to the sides (along the x axis), sometimes differently for the left and right eyes.
     
  7. CrazyTegger

    CrazyTegger

    Joined:
    Feb 15, 2015
    Posts:
    57
    @raziel, were you able to get it working with the plane of 1.0? What does this number represent - I don't recognize it.

    Yeah, I experience the same thing - left and right eye aren't matching up.
     
  8. CrazyTegger

    CrazyTegger

    Joined:
    Feb 15, 2015
    Posts:
    57
    I found this quote in a Unity VR tutorial:

    So what that means is that we must use World Space UI. We cannot use Screen Space. This would explain why the UI the way it did.
     
  9. Unity_Wesley

    Unity_Wesley

    Unity Technologies

    Joined:
    Sep 17, 2015
    Posts:
    558
    Hello,

    @CrazyTegger - If you would like to could create a Tag along behavior in a script and attach it to the canvas. I would suggest looking at the game robo raid on the Microsoft Windows Store (it is free), might help with that.

    The Microsoft Tool Kit might also have some helpful scripts and prefabs to help you with UI.

    Thank you,
    Wesley
     
Thread Status:
Not open for further replies.