I have a basic scene with 3 prefabs from the HoloToolkit-Unity package:
HololensCamera + InputManager + CursorWithFeedback
I then add a Canvas (and subsequently a Panel and a Button) to my scene, with the Canvas being in Screen Space - Camera and the HololensCamera being the Render Camera and of course everything was fine, until I noticed that when I run on device, the cube is there as a fixed game object (as one would expect!) but my whole Canvas seems like it is attached to the camera.
Why is this? How do I place a fixed Canvas in my scene?
Read through this
https://docs.unity3d.com/Manual/UICanvas.html
Notice the differences between Overlay/Screenspace/Worldspace
And also try to understand the relation between different camera's and UI elements. If afterwards you still don't understand i'll try to help you.
Related
New to unity so hoping this is a dumb / quick fix.
I'm using XR Interaction Toolkit's XR Origin camera (device-based if it matters) and want to add a second camera to overlay my UI elements so the canvases appear on top of walls / elements instead of intersecting and being hidden by them.
I've duplicated my main camera and removed all scripts except the main camera one, set it as a child to the previous main camera, and adjusted the culling masks to be UI-only and Everything-but-UI. I've also set the depth of the ui camera to be higher than the main camera, and set Clear Flags to Depth only. My UI elements are in the correct layer and the camera of the canvas is the child UI camera.
The result is a disaster. When I click the button to bring up my UI overlay, me view becomes a 360 pixelated block of tiny mirrored rectangles.
Any help would be appreciated, or workarounds not using 2 cameras.
Thanks all
I am new to Unity and am working on a UI project. I want to add a Camera targeted on a GameObject in the Canvas. There is a Camera with the same hierarchy of the Canvas and when I clicked it the preview is blank but when I play the project everything is shown, including all the buttons texts images.
How does the Camera work with UI and is it possible to add a camera targeted on a GameObject?
For your main Canvas, you do not need a Camera. Please see the Unity Manual for information regarding the Canvas. Take note of the Render Mode option on the Canvas Component. If this is set to Screen Space - Overlay then you will not need a camera to view UI Items or GameObjects that are placed as children to this GameObject. It will also inherently not appear in your Camera Preview if it is located under a Canvas of this type.
If you would like to have other GameObjects show up in the Camera Preview, add them to your scene and ensure that they are not under the Canvas GameObject. Then ensure that they are in range of your Camera.
Hope this helps!
I have a VR project for which I am trying to render a canvas to be "always on top" of everything using a separate UI camera as noted here.
I made my UICamera object a child of the main camera - which is the centerEyeAnchor object in the OVRCameraRig.
And I set the culling mask for my UICamera to only show its layer and removed that layer from the main camera (CenterEyeAnchor).
But in fact the perspective is weird and it seems like the UICamera is offset a little bit but its transform is zero'd out in the inspector, so I don't why it's displaying so weird.
If I set the culling mask to "Everything" for both cameras it's still offset a little.
In general you don't need the UI camera to be a child of CenterEyeAnchor. Move it out to to the top level and zero out the coordinates. The Oculus rig might be doing some magic with IPD or something else and it screws up the pixel-perfectness of UI.
I am using Unity on a 2D game(I am very amateur on it still) and while using Create->UI->Image to add a new sprite works fine, whenever I drag and drop an image from my assets folder, it always lies behind the background that I have set up for my canvas, regardless of whether i use a higher sort order, if the image is a child of the canvas or the layer is the same for all my canvas elements(UI or default). Also getting the same when attempting to drag an animation.
I was reading somewhere that the canvas is kinda like another UI element and that the image would have to be a child of it in order to display above it, but even when i dragged it as a child to the canvas, I am still getting the same result. Other ideas were about using the world space mode, which appears to be fixing it for the sprite, but I am just not sure on why.
Can somebody explain what is happening ? I wasn't really able to find a good resource that explains it in such a way that would help me understand. Thanks !
In screenspace mode, the Canvas always renders on top of the normal scene objects (by design). Dropping types that inherit from UnityEngine.Object (such as sprites) into the Canvas hierarchy do not place them on the screenspace canvas, but rather in the (2D)3D scene (even though they are in the Canvas hierarchy). In order to get an image to adhere to the Canvas visual sorting depth (order in hierarchy), you'd have to place a UnityEngine.UI.Image and then add the resource sprite to it (as you appear to have discovered). At this point you can control the 'depth' of the sprite resource only with respect to other Canvas UI objects and it will always be on top of other scene-based objects.
In other words, the Canvas and its UnityEngine.UI objects (in screenspace mode) will always render on top of your normal scene objects (i.e. like a HUD). In worldspace mode, each Canvas object (and its UnityEngine.UI children) can be positioned in the 3D scene as though it is a normal scene object (more or less).
This is my first time with unity, I need to make a 3d object in the camera of the device (vr) in certain coordinates of a map, do you know any links that can help me? Is only a static object will always be in the same position and users will be able to see it on their devices
If this is to be overlayed above a 3D scene use a renderTexture, then add the rendered texture to the UI using a Raw Image component.
Another way to do this is to use a canvas set to screen space overlay rendering. You can create a canvas by going to GameObject > UI > Image.
(see page for UI>canvas on Unity manual site, I can only post 2 links as a new user)
The canvas in this rendering mode is described this way on the unity manual page for the UI Canvas:
Screen Space - Overlay
This render mode places UI elements on the screen rendered on top of the scene. If the screen is resized or changes resolution, the Canvas will automatically change size to match this.
I am assuming this is a UI element over a 3D scene, because you mentioned VR.
Credit: I got some of my links and info from the unity forum thread "What is the best way to display 3D models as UI elements?"