Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Sprite is constantly behind background[IMG]

Discussion in '2D' started by Jardis01, Mar 25, 2020.

  1. Jardis01

    Jardis01

    Joined:
    Mar 24, 2020
    Posts:
    5
    Hi, I have a problem where I can't get the sprite to be in my game view.
    Even when I disable the background image, I can't get the sprite to show in the gameview.

    Another thing I've noticed is that when I drag the spritesheet in under Canvas, instead of putting it on top of the canvas like other UI elements, it gets placed down in the left corner like a tiny sprite, within the camera view?
    I've also tried to put the sprite itself in front of the Canvas, but as you can see by the pictures I've posted aswell, the sprite gets clipped out somehow.

    Any idea how to fix this?

    (The images I've uploaded are from 3D view of the game, showcasing how the sprite iself is clipping behind the Canvas, even though it is in front.)

    Cheers!
    67225b6b9959420db200987a7fe1de26.png
    fb5c6eef1e4b72e76144de4bdab2d6c0.png
     
  2. Lo-renzo

    Lo-renzo

    Joined:
    Apr 8, 2018
    Posts:
    1,323
    Are these both Images on the Canvas? The Canvas is for UI elements. By default, UI images render in front of everything else.

    SpriteRenderers, in contrast, will sort against one another depending on (1) Sorting Layer, (2) Sorting Order, (3) z-level. I have a feeling that you mean to instead use SpriteRenderers in the scene, as opposed to on the canvas. If you want these to be rendered as UI, then Canvas images (absent a Sorting Groups) render in the hierarchy order. Rearrange the hierarchy will rearrange what renders on top of what.

    To fix, you should either take it all off the the Canvas and then use sorting layer/order/z with SpriteRenderers, or - if this is supposed to be UI - put it all on the Canvas with Image components.
     
  3. Jardis01

    Jardis01

    Joined:
    Mar 24, 2020
    Posts:
    5
    The sprite is moving, aswell as it's gonna be interactable, as in if you press it it makes a sound for example. But even if I try to make the sprite itself outside of the canvas, it doesn't show in the game scene, it's just white, but the other UI elements shows though. Should the sprite not be child of canvas?

    When I try to put the sprite outside of canvas it doesn't work either...
     
  4. Lo-renzo

    Lo-renzo

    Joined:
    Apr 8, 2018
    Posts:
    1,323
    SpriteRenderer supposed to be outside Canvas. Image, on the other hand, is similar but for Canvas. It would be helpful to see what you're seeing with it appearing white.
     
  5. Jardis01

    Jardis01

    Joined:
    Mar 24, 2020
    Posts:
    5
    I fixed it, thanks! I had to use a image, and make it a image.sprite, and it worked perfectly!