- Home /
Canvas is hiding my 3D model, can I place the model in front of the canvas?
So I have a Canvas with several elements on it and a 3D model (robot) which is not part of the canvas.
There is one camera in the scene so far and it is pointing at the robot. So when I run the game, it looks something like this (I have replaced the actual model with Unity objects for now):
The canvas render mode is set to "Screen Space - Overlay".
Here's the problem, I am using a panel for the background and its alpha is set to 0 which is why you can see the model in the picture. However, as soon as I add a background, the model disappears and sits behind the canvas like in this picture
So now I am wondering if I should be using a second camera or if there is a way around it.
What do you guys think?
Answer by James2Games · Jan 19, 2017 at 08:45 PM
In situations like this I like to use multiple cameras to separate the layers of what we can see. For this I would use 1 camera for the UI and 1 for the model and controls the background.
Another option is to use a third camera for the background in case you want to add things that can only be seen in the background and can mean you can change the background to what you like without effecting the model or UI.
Thank you for the reply.
Quick question, what do you mean when you saud "and controls the background"?
Another thing, the main camera is assigned to the robot and the new camera is assigned to the Canvas. How do you blend both worlds together in this case? Do you have to control the depth of the cameras? Are there layers I need to switch on/off? A hierarchy of some sort?
Thanks again!
A way to think of it is what the 3 cameras would represent how the world is presented.
The ui camera shows what happens in front of the model. The model camera only shows the model and only the model. The background camera shows what happens behind the model. So when you change what the background camera sees. It will change what is seen behind the model.
It's tedius to setup and understand at first but afterwards it gets easier.
Ui camera -
Set depth to 3
Set clearing type to 'don't clear'
$$anonymous$$odel camera
Depth = 2
Clearing type = don't clear
Background camera
Depth = 1
Clearing type = sky or solid color
Extending this so you don't get the model viewed multiple times or the background looking funky. You can change the culling on the camers to render certain layers. Example ui camera should only have the ui tag set.
Edit:
The '$$anonymous$$ain Camera' tag is only used when trying to find a camera via code. Camera.main looks for a camera with the '$$anonymous$$ain Camera' tag and returns that.
So the way you have it set up is the main camera is the model camera in my description above
The order of cameras in the hierarchy doesn't effect how they are seen in-game. That's all done through the Cameras options.
Thank you for the answer. I will try it out and get back to you!
Your answer
Follow this Question
Related Questions
The camera doesn't match with canvas 1 Answer
How to Adjust Size of objects/Camera's size for different resolutions 1 Answer
How to render canvas with screen space - camera on top of canvas with screen space - overlay? 2 Answers
I can't see my button in Game View! 3 Answers
Why use different Canvas Render Modes 0 Answers