- Home /
3D Objects on a UI canvas with LWRP?
Hi everyone,
I'm currently developing UI on a project and have encountered a bit of a snag in one of my current problems.
I'm intending to put 3D objects onto a canvas such that that are part of the UI. I investigated camera stacking a bit, but have learned that camera stacking isn't yet supported with LWRP. You can read more about that here: https://forum.unity.com/threads/glitching-with-multiple-cameras-lwrp.592477/
My current situation is this:
I have a screen overlay canvas for all UI elements. I have a prefab piece of UI that is dynamically added to the canvas as needed. Part of this prefab is a 3D model that is supposed to represent objects that the player character picks up. The model needs to be part of the UI prefab to preserve its position and sit alongside text and numerical information over the player character, like the amount of currency the player has picked up off the ground at some moment. So, I have 2D and 3D elements taking up canvas space as part of the same prefab.
I have tried separating the canvas into two unique canvases. The second [new] canvas was a camera overlay. Then, I created a second camera specifically to attach to this new canvas. I was intending on using the Clear Flags on this camera so that the 3D UI could sit over the other camera's render, but due to the previously mentioned issue with LWRP, Clear Flags are not supported as far as I know.
With my current set up - one canvas, one camera - I can see all of the 2D elements on the canvas, but none of the 3D elements. The 3D and 2D elements are part of the same object / prefab on the canvas, but I can only see the 2D parts of it in the game view. It is also worth noting that the 3D object is visible as intended in the scene view, but not the game view.
Has anyone attempted to solve a similar problem using LWRP? I would really appreciate some insight on drawing 3D objects on a canvas. More curiously, I would like to know why they are visible on the canvas in the scene view, but hidden in the game view.
hey, austin. Have you figured out a way to do this? I want to do something very similar and ran into the exact same situation you described here (with URP). 2D stuff is visible, when I pause I see the 3D objects where I would expect them, but in game, they are not visible.
Would be super helpful, if you found a way to do this.
Answer by kromenak · Jan 31, 2020 at 10:35 PM
I believe a canvas in "Screen Space - Overlay" mode will draw all its UI elements after objects in the scene and on top of any scene objects.
Even though you have 3D objects as part of the UI prefab, those 3D objects will NOT be drawn at the same time as the UI elements. I think what would happen is the 3D object would get drawn during scene rendering (per the properties of its material/shader) and the UI elements in the "Screen Space - Overlay" canvas would be drawn last and on top of everything, potentially obscuring your 3D object.
One suggestion I'd have is to try using "Screen Space - Camera" mode instead. This actually puts the UI canvas in your 3D world, some distance in front of a particular camera. In my testing, this then allows 3D objects to properly render in front of or behind the UI - you can just imagine that your UI and 3D model all exist as objects in front of the camera, which is exactly how you expect a camera to work in the real world.
You might run into some issues if you have overridden any settings that affect draw order of objects in the scene - for example, culling mask, camera depth, layers, canvas "sorting layer" and "order in layer", material render queue values, etc. But absent all of those complicating factors, I think this works correctly - at least, when I do a simple test in a scene with a single camera, screen space-camera canvas, a UI image, and a 3D cube, it seems to work fine.
Answer by Tarodev · May 04, 2021 at 12:59 AM
Here's a quick (2m) tutorial: https://www.youtube.com/watch?v=8yzpjkoE0YA
Your answer
Follow this Question
Related Questions
Canvas items turned to be blank images 0 Answers
How to create a "back" side of a canvas UI element 1 Answer
Custom Transparency Axis Canvas Rendering Order 0 Answers
Unity 5.2 Canvas component makes the position not to update 2 Answers
When does the UI system generate its list of draw commands? 1 Answer