Reputation: 2897
In my 2d Unity project, I have a Canvas with an Image that I want for a Background.
I have 2 gameObjects in front of this background. But no matter how much fiddling I do with Pos Z, Sorting Layers, or hierarchy sorting, the image is always in front of the objects.
Gif above shows in 3d mode that even though the image is clearly behind these objects, it will always appear over them if they overlap.
Hierarchy:
Any advice to rescue me from this madness is much appreciated.
Upvotes: 3
Views: 15165
Reputation: 1
In the end I solved it by changing the game objects into images instead - go to canvas and create new UI - image - and then attached the sprite that way... it worked for my context, but may not work with your set up :)
Upvotes: 0
Reputation: 21
I figured out a workaround. I basically created a VisualElement inside the UI Builder and set a render texture to the background. Then I added an extra camera to my project to view all the sprites that needed to be on top. That camera feeds the render texture, so now everything that camera sees is forced to be on top of the UI Document as the background of that VisualElement. If you want control over the whole screen, just set the VisualElement position to absolute and max out its dimensions. If your game doesn't have a fixed aspect ratio it might cause some stretching, but other than that I cant really tell the difference. Sorting layers for the UI Documents are broken and unity needs to work on that. This is the best option I've found. Hope this helps.
Upvotes: 2
Reputation: 16
Had this same issue and was able to fix it with these steps:
Upvotes: 0
Reputation: 397
Upvotes: 0
Reputation: 1
You could create a layer called Object Assign it to the game objects. Create an object camera culling mask -> object layer depth bigger than you current main camera. Set it to Projection -> Orthographic Clear flags -> solid colors. canvas Render Mode -> Screen Space - Camera and assign the Render Camera to be the Object Camera
Upvotes: 0
Reputation: 1
Try clicking on Layers -> edit layers
, inside sorting layers you can change the order grabbing layer, everything upper appears behind in the camera.
Upvotes: 0
Reputation: 1
I had the same problem and I fixed it by attaching the camera to the canvas which is screen space and finally changing the sorting layer of my object to -1.
Upvotes: -1
Reputation: 78
Set the sprite renderer's transform z value to 0 instead of 100
If that does not solve, please specify camera properties also, so I can try to recreate the exact setup.
Upvotes: 0