- Home /
Spriterenderer on top of canvases
I have two canvases. One with a background image and one with all overlaying elements like texts and such.
The background canvas has an order of 0, the overlay canvas of 1.
Now, I'd like to create an animating sprite on top of those canvases but I can't for the life of me get the sprite on top of the other images.
I can see the sprite being on top on the stage, but when I switch to gameview, it's gone! There are no scripts attached to the sprite. Only an animator(Which works fine when I play it).
Note:
My canvases have a render mode of Screen space - Overlay.
I've set the spriterenderer on Sorting Layer 9, order 300. Although it's the only sprite out there. layer 1 or order 1 didn't do anything different, though.
The other elements in the canvases are either UI texts or Images
All the elements in the canvases are on either BackgroundLayer or OverlayLayer
The canvases themselves are on the UI layer
Answer by rob5300 · Jan 30, 2015 at 06:18 PM
Try using different cameras, or using World space as the render mode. I am assuming here that this Sprite is in the scene, not in any canvas. I can explain using different cameras:
You can have multiple cameras in the scene, and they have a render depth which defines in what order they are drawn on screen. We can have our normal camera render the canvas's and other scene objects, we will set this up now!
We then create a new camera, in the same location (maybe as a child of the main to make them always move together). We can use the culling mask feature, where we can (by using layers) to define what this camera can see. We take the sprite and place it on separate layer and define that as all that camera can see. We also remove that layer from the main camera.
We now on the new camera, change the clear flags to not clear, so we can see the main cameras stuff. Lastly we set the depth to higher than our main camera. This makes sure it renders above the other cameras objects.
And that should of worked!! Please say if i miss-understood or it doesn't make sense!
NOTE: You may have to change the render mode of the canvas's from screen space overlay to Screen space camera, otherwise Unity renders the UI over everything, which is not what we want.
I'm using the screen space-overlay because I'm making an app. It makes sure All the texts etc. are relatively placed in their corners and won't move if the resolution of the device changes. Will this be an issue when changing render mode or camera?
Next question: Screen space - Camera seems to keep the resolution intact. I've made a second camera and only show the layer "Sprites". Excluded that one from the main Camera. And the new Camera has a "Don't clear" flag. Ive made an empty object "Spriteholder" and put that on the layer "Sprites" and put a sprite on it. I see the sprite on my stage, but yet again, not in my gameview.
Are you sure the sprite is in the view port of the camera? I can assume you are using Orthographic for the sprite. $$anonymous$$ake sure the sprite is inside the box shown in the inspector, and it isn't right against the camera as it has a near clipping plane too.
You've lost me. I have no idea what you mean. The second camera has Sprites as only culling mask. The sprite is on Sprites. The camera is orthographic. Can we chat in here or doesn't Unity Answers have a chat function? Edit: Here's a screenshot of my 2nd camera: http://i.imgur.com/X4eCiOu.png
Got it. Changing both camera's to Orthographic did the trick
Answer by omaglana · Aug 25, 2018 at 12:46 PM
The above answer is corrent but one thing that is forgotten is: Go to Canvas -> Render Camera: "Select the new Camera where Culling Mask is assigned at the designated layer