Search Unity

2D Character has no depth

Discussion in '2D' started by MilesWings, Oct 5, 2022.

  1. MilesWings

    MilesWings

    Joined:
    Nov 13, 2018
    Posts:
    2
    Hello
    I'm not a very experienced programmer and I'm stuck with a problem.

    I'm developing a 3D game with 2D sprites, kinda like Paper Mario, and my character is being imported into Unity with the PSB Importer. The character is made of various sprites, has bones and it's animated using Unity's animator.

    However it is being rendered weirdly and it always shows on top of other sprites, no matter how far it moves in the z axis.
    Since I want the game to have other characters using the same sprite structure, I don't want them to overlap like that, so I want them to be rendered relative to their postion and not their layer hierarchy.
    Any ideas?

    Screenshot_22.png Screenshot_23.png Screenshot_24.png
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,738
    Three (3) primary ways that Unity draws / stacks / sorts / layers / overlays stuff:

    https://forum.unity.com/threads/orthographic-camera-rendering-order.1114078/#post-7167037

    In short,

    1. The default 3D Renderers draw stuff according to Z depth - distance from camera.

    2. SpriteRenderers draw according to their Sorting Layer and Sorting Depth properties

    3. UI Canvas Renderers draw in linear transform sequence, like a stack of papers

    If you find that you need to mix and match items using these different ways of rendering, and have them appear in ways they are not initially designed for, you need to:

    - identify what you are using
    - search online for the combination of things you are doing and how to to achieve what you want.

    There may be more than one solution to try.

    Additional reading in the official docs:

    https://docs.unity3d.com/Manual/2DSorting.html

    And SortingGroups can also be extremely helpful in certain circumstances:

    https://docs.unity3d.com/Manual/class-SortingGroup.html
     
    MarekUnity and MilesWings like this.