Why the cube is transparent on the canvas/panel ui? - unity3d

I want to animate the cube over the ui panel.
The Canvas is set to Render Mode : Screen Space - Overlay
The Panel have my own source image
The Camera Clear Flags set to Skbox and Culling Mask to UI only
The Cube layer is set to UI
But the Cube is transparent and I want it to be full like a regular Cube.

I think #Draco18s is right, for you to render UI behind stuff you need to change the Canvas to Camera or World space and then configure Z position in transform of the background (or depth in canvas component) to make it stay behind your cube.
Remember to add a camera to the canvas.

Related

Unity Camera with RenderTexture problem, how to get the right output?

I have a scene need to display a 3d module to ui layer, so i use a secondary camera to render it to a RenderTexture, but when i set a background to the ui layer ,i found that the content is wrong, because the alpha channel is not what i expect
In order to describe my problem more clearly, I created a demo
the content: in the center has the backgorund color, this is what i don't want, i want the center is fully white
the 3d object: a cube with opaque material and sphere with transparent material
the renderTexture's alpha channel:
I tried use colormask to disable alpha output, but the ui layer background size is smaller than my 3d model's content, so where there is no background it is invisible.
Update at 2023-2-15-17:49
this is the problem in my project, the character's hair has some transparent part, i use a camera with renderTexture to display it on Ui layer, but the hair's transparent part make some mistake
Solution:
Set the RenderTexture's Color Format to ARGB32.
Make sure the background of the UI layer is fully opaque.
Enable Alpha Clipping in the material of the 3D object, and set the Alpha to the desired value.
Set the RenderTexture's Clear Flags to "Depth Only", so that the background color will not be taken into account.

Unity2D layering multiple canvas'

I have two canvas' set up for my project, one to act as a background and one to hold foreground UI elements. Originally they were set to world space, and I had no problems, but now I am optimizing my game, I must change the space so they adjust to mobile phones. How can I design the canvas' so that one acts in the background and the other in the foreground? I have tried changing the z-pos and other quick fixes I found online but none have worked.
Ok, you have background canvas, sprites and foreground canvas, and background canvas should be behind everything including sprites.
The idea is to render at first only background with one camera, and then render everything with another.
To do that, we should:
Add a layer for background canvas. Change layer of background canvas and children to that layer.
To add a layer, select any gameObject and in top of the inspector you will see:
Click on a dropdown list labeled "Layer" and select "Add Layer". Then create new layer and give it a name:
Select your background canvas and change layer for it and its children. When adding gameObjects, keep in mind that if you add them to background canvas, their layer must be the same as the layer of canvas, otherwise they will be rendered by the wrong camera.
Disable that layer in main camera's culling mask.
Now the camera should no longer render background UI, and it will disappear in the game view.
Add a camera for rendering background UI.
Cameras with higher depth render on top of those with lower depth, so we should set its depth to less than depth of main camera. We should also set its culling mask to only layer for background UI, otherwise all objects on scene will be rendered twice. Copy other setting from main camera. Set main camera's clear mode to Don't Clear or Depth Only to prevent it from erasing background.
Set mode of the background canvas to Screen Space - Camera and drag newly created camera into field "Render Camera" there.
It should work now.

Unity3d background

I'm trying to get an image to be a background on my camera. It's one picture, it doesn't need to be repeated. It would be nice to have it stretch out when the resolution of the screen changes. I've found older tutorials that show how todo it in an older version of unity, like this one: Link
However it seems that functionality is no longer in the newest version of Unity. Does anyone have any idea how to put a single picture as background?
thanks in advance.
Add a Canvas (UI --> Canvas) to your scene and set it's render mode to "Screen Space - Camera".
Set the Canvas' Render Camera to your scenes main camera (i.e. the camera you render your 3D scene with... or the only camera in the scene ;) )
make sure the Plane Distance of the Canvas is set to the far plane of your camera. So if your far clipping plane is set to 1000 set the Plane Distance to 1000 as well (or 999, if images in the canvas happen to be clipped away by the camera). If your Plane Distance is lower than the far clipping plane of your camera, objects behind the Plane Distance will be occluded by Images on the canvas.
Add an Image (UI --> Image) to the Canvas and set its anchor presets to strech on both axes.
Set the Left, Top, Right and Bottom Parameters of the Image's Rect Transform to 0. Now the image should be full screen and adjust to any change in the aspect ratio.
That should do the trick :)

Match Canvas with Main Camera - Unity

I want to use the Canvas and UI Text to constantly show the score of my game on the top right corner of the screen. How can I initialize the Canvas so that its position and dimensions perfectly match the border of the camera? (2D Setup)
To see the canvas fit into the camera's size in the scene, change the Canvas component's Render Mode to Screen Space - Camera, and drag the camera from the hierarchy to it.

Masking in World Space canvas - Gameobject renderers act as mask too

My goal was to create a Scroll Rect on a worldspace canvas but whenever I would mask out the content everything vanished. I tested on an overlay canvas to see if I was setting it up correctly and I was.
What I learned was that non-UI gameobject renderers were being used as the mask too so if there was something being rendered in world space, it would mask the Scroll Rect Content.
The top image shows the mask disabled. The bottom shows the mask enabled.
Any ideas how I can have it ignore the worldspace objects?!
Not saying this is an answer but changing the main camera from Deferred rendering to Forward will fix this.