0
0
Unityframework~20 mins

Sprite creation and import in Unity - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Sprite Mastery Badge
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 Unity C# code when importing a sprite?
Consider this code snippet that loads a sprite from the Resources folder and assigns it to a GameObject's SpriteRenderer. What will be the result when this code runs?
Unity
using UnityEngine;

public class SpriteLoader : MonoBehaviour {
    void Start() {
        SpriteRenderer sr = gameObject.AddComponent<SpriteRenderer>();
        Sprite sprite = Resources.Load<Sprite>("MySprite");
        sr.sprite = sprite;
        Debug.Log(sr.sprite.name);
    }
}
ADoes nothing because Resources.Load does not work in Start()
BThrows a NullReferenceException because sprite is null
CPrints "SpriteRenderer" and shows a default white square sprite
DPrints "MySprite" in the console and displays the sprite on the GameObject
Attempts:
2 left
💡 Hint
Remember that Resources.Load looks for assets inside a Resources folder and returns null if not found.
🧠 Conceptual
intermediate
1:30remaining
Which import setting affects sprite slicing in Unity?
When importing a sprite sheet in Unity, which import setting determines how the sprite is sliced into multiple sprites?
ASprite Mode set to Multiple
BPixels Per Unit value
CFilter Mode set to Point
DCompression set to None
Attempts:
2 left
💡 Hint
Think about how Unity knows to treat the image as one or many sprites.
🔧 Debug
advanced
2:00remaining
Why does this sprite not display after import?
You imported a PNG sprite into Unity and assigned it to a SpriteRenderer, but it does not show in the game view. What is the most likely cause?
Unity
SpriteRenderer sr = gameObject.GetComponent<SpriteRenderer>();
sr.sprite = Resources.Load<Sprite>("MySprite");
AThe sprite is compressed with high quality
BThe sprite's Pixels Per Unit is too high
CThe sprite's Texture Type is set to Default instead of Sprite (2D and UI)
DThe sprite's Filter Mode is set to Bilinear
Attempts:
2 left
💡 Hint
Check the Texture Type in the import settings.
📝 Syntax
advanced
2:00remaining
Which code correctly creates a sprite from a texture at runtime?
You have a Texture2D object and want to create a sprite from it in code. Which option is correct?
ASprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f, 0.5f));
Bnew Sprite(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f, 0.5f));
CSprite.Create(texture, new Vector2(0.5f, 0.5f), new Rect(0, 0, texture.width, texture.height));
DSprite.New(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f, 0.5f));
Attempts:
2 left
💡 Hint
Check the Sprite.Create method signature.
🚀 Application
expert
1:30remaining
How many sprites are created after slicing this sprite sheet?
You import a 256x256 pixel sprite sheet and set Sprite Mode to Multiple. You slice it into 16 equal squares using the Sprite Editor grid slicing. How many sprites are created?
A8
B16
C32
D4
Attempts:
2 left
💡 Hint
Calculate how many 64x64 squares fit into 256x256.