Bird
Raised Fist0
Unityframework~20 mins

Sorting layers and order in Unity - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Sorting Layers Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
2:00remaining
What is the output of sorting order values?
Consider two GameObjects with SpriteRenderer components. One has sortingLayerName = "Background" and sortingOrder = 2, the other has sortingLayerName = "Foreground" and sortingOrder = 1. Which one will appear on top in the game view?
Unity
SpriteRenderer bgRenderer = backgroundGameObject.GetComponent<SpriteRenderer>();
SpriteRenderer fgRenderer = foregroundGameObject.GetComponent<SpriteRenderer>();

// Background layer order
Debug.Log($"Background layer order: {bgRenderer.sortingOrder}");
// Foreground layer order
Debug.Log($"Foreground layer order: {fgRenderer.sortingOrder}");
AThe Background object appears on top because its sortingOrder is 2.
BBoth objects appear at the same level because sortingOrder values are ignored when sortingLayerNames differ.
CThe Foreground object appears on top because its sortingLayerName is "Foreground" which is above "Background" regardless of sortingOrder.
DThe Background object appears on top because sortingLayerName "Background" has higher priority than "Foreground".
Attempts:
2 left
💡 Hint
Remember that sorting layers have a priority order set in Unity, and sortingOrder only affects order within the same layer.
❓ Predict Output
intermediate
1:30remaining
What is the sorting order after changing it at runtime?
You have a SpriteRenderer with sortingOrder = 5. You run this code: spriteRenderer.sortingOrder = 10; What is the sortingOrder value after this code runs?
Unity
spriteRenderer.sortingOrder = 10;
Debug.Log(spriteRenderer.sortingOrder);
A10
BIt throws an error because sortingOrder is read-only.
C0
D5
Attempts:
2 left
💡 Hint
Think about whether sortingOrder can be changed at runtime.
❓ Predict Output
advanced
2:30remaining
What is the output of this sorting layer comparison code?
Given two SpriteRenderers with the same sortingOrder but different sortingLayerIDs, what does this code print? ```csharp int result = spriteRendererA.sortingLayerID.CompareTo(spriteRendererB.sortingLayerID); Debug.Log(result); ```
Unity
int result = spriteRendererA.sortingLayerID.CompareTo(spriteRendererB.sortingLayerID);
Debug.Log(result);
AAlways 0 because sortingLayerID is the same for all layers.
BAlways positive because sortingLayerID is a unique positive number.
CThrows a runtime error because sortingLayerID is not comparable.
D0 if both are on the same sorting layer, positive if A's layer is above B's, negative if below.
Attempts:
2 left
💡 Hint
sortingLayerID is an integer representing the layer's priority.
❓ Predict Output
advanced
2:30remaining
What happens if two objects share the same sorting layer and order?
Two GameObjects have SpriteRenderers with sortingLayerName = "Default" and sortingOrder = 0. What determines which one is drawn on top?
AThe one created last in the scene hierarchy is drawn on top.
BThe one with the lower Z position is drawn on top.
CThe draw order is undefined and may flicker between frames.
DThe one with the higher instance ID is drawn on top.
Attempts:
2 left
💡 Hint
When sorting layers and orders are equal, Unity uses the object's position in 3D space.
🧠 Conceptual
expert
3:00remaining
How to ensure UI elements always appear above sprites using sorting layers?
You want UI elements to always appear above all sprites in your scene. Which approach ensures this reliably?
ASet UI Canvas sortingLayerName to a layer above all sprite layers and set sortingOrder high enough.
BSet UI Canvas sortingLayerName to "Default" and sortingOrder to 0.
CChange the Z position of UI elements to be higher than sprites.
DUse the same sorting layer as sprites but set sortingOrder to a negative number.
Attempts:
2 left
💡 Hint
Think about sorting layers priority and how UI Canvas uses them.

Practice

(1/5)
1. What is the main purpose of Sorting Layers in Unity?
easy
A. To apply physics properties to objects
B. To change the physical position of objects in the scene
C. To set the color of objects
D. To group objects and control their visual stacking order

Solution

  1. Step 1: Understand Sorting Layers concept

    Sorting Layers are used to group objects so Unity knows which objects appear in front or behind others visually.
  2. Step 2: Differentiate from other properties

    Sorting Layers do not move objects physically or change physics or color; they only affect visual stacking order.
  3. Final Answer:

    To group objects and control their visual stacking order -> Option D
  4. Quick Check:

    Sorting Layers = Visual stacking order [OK]
Hint: Sorting Layers control visual order, not position or physics [OK]
Common Mistakes:
  • Confusing sorting layers with object position
  • Thinking sorting layers affect physics
  • Assuming sorting layers change object color
2. Which of the following is the correct way to set the sorting order of a SpriteRenderer component in Unity C# script?
easy
A. spriteRenderer.orderSorting = 5;
B. spriteRenderer.sortOrder = 5;
C. spriteRenderer.sortingOrder = 5;
D. spriteRenderer.layerOrder = 5;

Solution

  1. Step 1: Recall SpriteRenderer property names

    The correct property to set the order within a sorting layer is sortingOrder.
  2. Step 2: Check each option for syntax correctness

    Only spriteRenderer.sortingOrder is a valid property; others are incorrect or do not exist.
  3. Final Answer:

    spriteRenderer.sortingOrder = 5; -> Option C
  4. Quick Check:

    Correct property name = sortingOrder [OK]
Hint: Use 'sortingOrder' property to set order in script [OK]
Common Mistakes:
  • Using incorrect property names like sortOrder
  • Confusing sorting layer with sorting order
  • Trying to set sorting layer with sortingOrder
3. Given two sprites in the same sorting layer with these orders:
spriteA.sortingOrder = 3;
spriteB.sortingOrder = 7;
Which sprite will appear on top visually?
medium
A. spriteB will appear on top
B. spriteA will appear on top
C. Both sprites will appear at the same level
D. Sorting order does not affect visual stacking

Solution

  1. Step 1: Understand sorting order within the same layer

    Higher sortingOrder values appear in front of lower ones within the same sorting layer.
  2. Step 2: Compare the given sortingOrder values

    spriteB has sortingOrder 7, which is higher than spriteA's 3, so spriteB appears on top.
  3. Final Answer:

    spriteB will appear on top -> Option A
  4. Quick Check:

    Higher sortingOrder = on top [OK]
Hint: Higher sortingOrder means sprite is drawn on top [OK]
Common Mistakes:
  • Thinking lower sortingOrder is on top
  • Confusing sorting layer with sorting order
  • Assuming sorting order has no effect
4. You set two sprites to the same sorting layer and sorting order, but one still appears behind the other unexpectedly. What is a likely cause?
medium
A. The sprite behind has a higher Z position in 3D space
B. Sorting layers override all other settings
C. Sorting order must be negative to appear on top
D. You must assign different sorting layers to fix this

Solution

  1. Step 1: Understand sorting layers and order limits

    Sorting layers and order control 2D visual stacking but Z position can still affect rendering if using 3D or perspective camera.
  2. Step 2: Identify cause of unexpected order

    If sorting layers and order are equal, the sprite with lower Z position (closer to camera) appears on top.
  3. Final Answer:

    The sprite behind has a higher Z position in 3D space -> Option A
  4. Quick Check:

    Z position affects draw order if sorting order is equal [OK]
Hint: Check Z position if sorting order is equal [OK]
Common Mistakes:
  • Assuming sorting layers always override Z position
  • Thinking sorting order must be negative
  • Believing different sorting layers are always required
5. You have three sprites: spriteX on sorting layer "Background" order 0, spriteY on sorting layer "Foreground" order 0, and spriteZ on sorting layer "Background" order 5.
Which sprite will appear on top visually?
hard
A. spriteZ will appear on top
B. spriteY will appear on top
C. spriteX will appear on top
D. spriteX and spriteY will appear on top together

Solution

  1. Step 1: Understand sorting layer priority

    Sorting layers have a fixed order set in Unity's editor. "Foreground" layer is above "Background" layer regardless of sortingOrder values.
  2. Step 2: Compare sprites across layers and orders

    spriteY is on "Foreground" layer order 0, which is above both spriteX and spriteZ on "Background" layer, even though spriteZ has order 5.
  3. Final Answer:

    spriteY will appear on top -> Option B
  4. Quick Check:

    Sorting layer priority beats sorting order [OK]
Hint: Sorting layer priority beats sorting order [OK]
Common Mistakes:
  • Thinking sorting order overrides sorting layer
  • Ignoring sorting layer hierarchy
  • Assuming higher order always means on top
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard