Bird
Raised Fist0
Unityframework~20 mins

Tilemap painting in Unity - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Tilemap Painting 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 this Tilemap painting code?

Consider this Unity C# script snippet that paints tiles on a Tilemap. What will be the color of the tile at position (1, 1) after running this code?

Unity
using UnityEngine;
using UnityEngine.Tilemaps;

public class PaintTiles : MonoBehaviour {
    public Tilemap tilemap;
    public TileBase tile;

    void Start() {
        Vector3Int pos = new Vector3Int(1, 1, 0);
        tilemap.SetTile(pos, tile);
        tilemap.SetColor(pos, Color.red);
        tilemap.SetColor(new Vector3Int(0, 0, 0), Color.blue);
    }
}
AThe tile at (1,1) is transparent (no color).
BThe tile at (1,1) is red.
CThe tile at (1,1) has the default color (white).
DThe tile at (1,1) is blue.
Attempts:
2 left
💡 Hint

Remember that SetColor changes the color of the tile at the specified position.

🧠 Conceptual
intermediate
1:30remaining
Which method paints a tile on a Tilemap in Unity?

In Unity's Tilemap system, which method is used to place a tile at a specific grid position?

Atilemap.SetTile(Vector3Int position, TileBase tile)
Btilemap.PlaceTile(Vector3Int position, TileBase tile)
Ctilemap.AddTile(Vector3Int position, TileBase tile)
Dtilemap.PaintTile(Vector3Int position, TileBase tile)
Attempts:
2 left
💡 Hint

Look for the official Unity Tilemap API method that sets a tile.

🔧 Debug
advanced
2:30remaining
Why does this Tilemap painting code not show the tile?

Look at this code snippet. Why does the tile not appear on the Tilemap after running?

Unity
using UnityEngine;
using UnityEngine.Tilemaps;

public class PaintTiles : MonoBehaviour {
    public Tilemap tilemap;
    public TileBase tile;

    void Start() {
        Vector3 pos = new Vector3(2, 2, 0);
        tilemap.SetTile(Vector3Int.FloorToInt(pos), tile);
    }
}
AVector3Int.FloorToInt(pos) is invalid and causes a runtime error.
BUsing Vector3 instead of Vector3Int causes the tile not to appear.
CThe tile variable is not assigned, so no tile is painted.
DTilemap.SetTile requires a Vector3 position, not Vector3Int.
Attempts:
2 left
💡 Hint

Check if the tile variable has a value before painting.

📝 Syntax
advanced
2:00remaining
Which option correctly paints multiple tiles in a loop?

Which code snippet correctly paints tiles at positions (0,0), (1,0), and (2,0) on a Tilemap?

Afor (int x = 0; x < 3; x++) { tilemap.SetTile(new Vector3Int(x, 0, 0), tile); }
Bfor (int x = 0; x < 3; x++) { tilemap.SetTile(new Vector3(x, 0, 0), tile); }
Cfor (int x = 0; x < 3; x++) { tilemap.SetTile(new Vector2Int(x, 0), tile); }
Dfor (int x = 0; x < 3; x++) { tilemap.SetTile(new Vector2(x, 0), tile); }
Attempts:
2 left
💡 Hint

Tilemap.SetTile requires a Vector3Int position.

🚀 Application
expert
3:00remaining
How many tiles are painted after this code runs?

Given this code, how many tiles will be painted on the Tilemap?

Unity
using UnityEngine;
using UnityEngine.Tilemaps;

public class PaintTiles : MonoBehaviour {
    public Tilemap tilemap;
    public TileBase tile;

    void Start() {
        for (int x = 0; x < 3; x++) {
            for (int y = 0; y < 3; y++) {
                if ((x + y) % 2 == 0) {
                    tilemap.SetTile(new Vector3Int(x, y, 0), tile);
                }
            }
        }
    }
}
A9 tiles
B6 tiles
C4 tiles
D5 tiles
Attempts:
2 left
💡 Hint

Count how many (x,y) pairs from 0 to 2 satisfy (x + y) % 2 == 0.

Practice

(1/5)
1. What does the SetTile method do in Unity's Tilemap painting?
easy
A. It resizes the tilemap grid.
B. It changes the color of the entire tilemap.
C. It places or removes a tile at a specific grid position.
D. It saves the tilemap as an image file.

Solution

  1. Step 1: Understand the purpose of SetTile

    The SetTile method is used to place or remove tiles at specific positions on the tilemap grid.
  2. Step 2: Compare with other options

    Changing color, resizing grid, or saving as image are not functions of SetTile.
  3. Final Answer:

    It places or removes a tile at a specific grid position. -> Option C
  4. Quick Check:

    SetTile = Place or remove tile [OK]
Hint: Remember SetTile changes tiles at grid spots [OK]
Common Mistakes:
  • Thinking SetTile changes tilemap color
  • Confusing SetTile with resizing grid
  • Assuming SetTile exports images
2. Which of the following is the correct syntax to set a tile at position (2, 3) on a Tilemap named tilemap using a tile named myTile?
easy
A. tilemap.SetTile(new Vector2(2, 3), myTile);
B. tilemap.SetTile(2, 3, myTile);
C. tilemap.SetTile(Vector3(2, 3), myTile);
D. tilemap.SetTile(new Vector3Int(2, 3, 0), myTile);

Solution

  1. Step 1: Identify correct parameter types for SetTile

    The SetTile method requires a Vector3Int for grid position and a tile object.
  2. Step 2: Check each option's syntax

    tilemap.SetTile(new Vector3Int(2, 3, 0), myTile); uses new Vector3Int(2, 3, 0) which is correct. Options A, B, and D use wrong types or missing 'new' keyword.
  3. Final Answer:

    tilemap.SetTile(new Vector3Int(2, 3, 0), myTile); -> Option D
  4. Quick Check:

    SetTile needs Vector3Int position [OK]
Hint: Use Vector3Int for tile positions in SetTile [OK]
Common Mistakes:
  • Using Vector2 instead of Vector3Int
  • Omitting 'new' keyword for Vector3Int
  • Passing separate x,y instead of Vector3Int
3. Given the code below, what will be the output on the tilemap?
Vector3Int pos = new Vector3Int(1, 1, 0);
tilemap.SetTile(pos, myTile);
tilemap.SetTile(pos, null);
medium
A. The tile at position (1,1) will be removed (empty).
B. The tile at position (1,1) will be set to myTile.
C. An error occurs because the same position is set twice.
D. The tilemap will have two tiles at position (1,1).

Solution

  1. Step 1: Understand SetTile behavior with null

    Setting a tile to null removes the tile at that position.
  2. Step 2: Analyze the code sequence

    First, the tile at (1,1) is set to myTile. Then it is immediately removed by setting it to null.
  3. Final Answer:

    The tile at position (1,1) will be removed (empty). -> Option A
  4. Quick Check:

    SetTile with null removes tile [OK]
Hint: SetTile with null clears tile at position [OK]
Common Mistakes:
  • Thinking setting twice causes error
  • Assuming tile remains after setting null
  • Believing multiple tiles can stack at one position
4. What is wrong with this code snippet that tries to paint a tile?
Vector3Int position = new Vector3Int(0, 0, 0);
tilemap.SetTile(position, myTile);
position = new Vector3Int(1, 0);
tilemap.SetTile(position, myTile);
medium
A. SetTile cannot be called twice in a row.
B. The second Vector3Int is missing the z coordinate.
C. The variable 'position' cannot be reassigned.
D. myTile is not defined before use.

Solution

  1. Step 1: Check Vector3Int constructor usage

    The first Vector3Int has three coordinates (x, y, z). The second only has two, which is invalid.
  2. Step 2: Understand Vector3Int requirements

    Vector3Int requires three integer arguments; missing the z coordinate causes a compile error.
  3. Final Answer:

    The second Vector3Int is missing the z coordinate. -> Option B
  4. Quick Check:

    Vector3Int needs 3 ints [OK]
Hint: Always provide x, y, and z for Vector3Int [OK]
Common Mistakes:
  • Assuming Vector3Int can have 2 parameters
  • Thinking SetTile calls cause errors
  • Believing variables can't be reassigned
5. You want to paint a 3x3 square of tiles starting at position (0,0) on a Tilemap named tilemap using a tile named grassTile. Which code snippet correctly does this?
hard
A. for (int x = 0; x < 3; x++) { for (int y = 0; y < 3; y++) { tilemap.SetTile(new Vector3Int(x, y, 0), grassTile); } }
B. for (int i = 0; i < 9; i++) { tilemap.SetTile(new Vector3Int(i, i, 0), grassTile); }
C. tilemap.SetTile(new Vector3Int(0, 0, 0), grassTile); tilemap.SetTile(new Vector3Int(1, 1, 0), grassTile); tilemap.SetTile(new Vector3Int(2, 2, 0), grassTile);
D. tilemap.SetTile(new Vector3Int(0, 0, 0), grassTile); tilemap.SetTile(new Vector3Int(0, 1, 0), grassTile); tilemap.SetTile(new Vector3Int(0, 2, 0), grassTile);

Solution

  1. Step 1: Understand the goal to paint a 3x3 square

    We need to paint tiles at all positions where x and y range from 0 to 2.
  2. Step 2: Analyze each code snippet

    for (int x = 0; x < 3; x++) { for (int y = 0; y < 3; y++) { tilemap.SetTile(new Vector3Int(x, y, 0), grassTile); } } uses nested loops for x and y from 0 to 2, correctly covering all 9 positions. for (int i = 0; i < 9; i++) { tilemap.SetTile(new Vector3Int(i, i, 0), grassTile); } paints diagonal only. tilemap.SetTile(new Vector3Int(0, 0, 0), grassTile); tilemap.SetTile(new Vector3Int(1, 1, 0), grassTile); tilemap.SetTile(new Vector3Int(2, 2, 0), grassTile); paints only three diagonal tiles. tilemap.SetTile(new Vector3Int(0, 0, 0), grassTile); tilemap.SetTile(new Vector3Int(0, 1, 0), grassTile); tilemap.SetTile(new Vector3Int(0, 2, 0), grassTile); paints only one column.
  3. Final Answer:

    for (int x = 0; x < 3; x++) { for (int y = 0; y < 3; y++) { tilemap.SetTile(new Vector3Int(x, y, 0), grassTile); } } -> Option A
  4. Quick Check:

    Nested loops cover 3x3 grid [OK]
Hint: Use nested loops for grid painting [OK]
Common Mistakes:
  • Painting only diagonal tiles
  • Painting fewer tiles than needed
  • Using single loop for 2D grid
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