3D characters are possible in 2D games and scenes. However, since Follow Sorting Maps are only able to control the dislay order of sprite shaders, it's not possible to properly control their depth display (relative to other scene objects and characters) without relying on a custom shader.
This script offers an alternative approach - by having each object and character rendered by a separate camera, and then controlling the display order of each camera.
(Note: This script requires AC v1.64.0 or later)
To use this method:
- Set up the scene's Sorting Map as normal, and place Follow Sorting Maps on your character(s).
- Place each character, and mid-scene sprite (i.e. objects the characters can move in front of and behind) on separate, dedicated layers - e.g. place the Player on a layer named "Player", a chair object on "Chair" etc.
- Create a new Camera for each new layer as a child of the MainCamera. Set the Clear Flags to Depth only, and the Culling Mask to just one of these new layers each.
- Attach the script below onto each new Camera. For cameras that render characters, assign that character's Follow Sorting Map in the script's Inspector.
- For cameras that render scene sprites, set the Camera's Depth value to match that sprite's Sorting Order value.
- Remove these new layers from the MainCamera's Culling Mask field.
public class SortingDepthCam : MonoBehaviour
private Camera ownCamera;
public FollowSortingMap followSortingMap;
private void Start ()
ownCamera = GetComponent <Camera>();
private void LateUpdate ()
ownCamera.transform.position = Camera.main.transform.position;
ownCamera.transform.rotation = Camera.main.transform.rotation;
ownCamera.projectionMatrix = Camera.main.projectionMatrix;
ownCamera.orthographicSize = Camera.main.orthographicSize;
ownCamera.fieldOfView = Camera.main.fieldOfView;
if (followSortingMap != null)
ownCamera.depth = followSortingMap.SortingOrder - ((float) followSortingMap.SharedDepth / 10f);