Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

Problem with UI being covered by 3D objects

A topic by Saurian246 created May 24, 2022 Views: 203 Replies: 4
Viewing posts 1 to 3
Submitted

I have run into a problem with Unity's UI that I can't seem to solve.

As you can see from the picture above, the 3D space turret is blocking the UI around it. This can make it very hard or even impossible for the player to click on the buttons when there are enemies, obstacles, and other stuff all around it. Is there some way of having the canvas or UI elements overlay in front of the world's 3D objects? I would appreciate any ideas!

Submitted

Hello there, You can always use the world space - overlay to put the specific canvas for the turret however you like. If you plan on having the UI always facing the camera you can create a script that will rotate the canvas depending on the forward vector of the camera. I do not know if it is the most efficient (or if that is what you want to achieve), but it is the first thing that comes to my head. Hope it helps

Submitted

Hi, I appreciate your response! I currently am using the world space render mode for the canvas, that way I set the position of the canvas to be where the turret is. But since it is in 3D space other 3D objects will be rendered in front of the canvas if they are between it and the camera. Here is a demonstration of what I was able to do with TMP text that I would like to do with the canvas:

The text, although its position is below the terrain in the world, is still rendered in front of the terrain, causing it to be visible under any circumstances. I was able to achieve this with a shader option, but you can't use shaders with UI elements. (at least not that I know of)


But I do think your idea of having the text always facing the camera can work as a work-around! I'll use that idea if I can't figure anything else out. Thanks for the help!

Submitted (1 edit) (+2)

For overlaying UI stuff that should appear in front of everything else (but has to be within the world scene), I usually use a separate camera with a higher Depth than the main camera and set that separate camera  with Depth Only for its Clear Flags. I set that camera with a culling mask that only display layers with the stuff I need to display in it and turn those layers off on the main camera. (You can set that secondary camera as the children of the main camera if you move the main around.) You can set that secondary UI camera as the camera for your World Space rendering UI.

Submitted

Thanks a ton! That works perfectly! I've never used multiple cameras before, but I think I will be doing it a lot from now on!