0
0
Unityframework~20 mins

ScriptableObjects for game data in Unity - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
ScriptableObject Mastery
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 ScriptableObject data access?

Consider a ScriptableObject named WeaponData with a field damage. The following code loads the asset and prints the damage value.

WeaponData weapon = Resources.Load<WeaponData>("Sword");
Debug.Log(weapon.damage);

Assuming the Sword asset has damage = 15, what will be printed?

Unity
WeaponData weapon = Resources.Load<WeaponData>("Sword");
Debug.Log(weapon.damage);
Anull
B0
C15
DThrows NullReferenceException
Attempts:
2 left
💡 Hint

Resources.Load returns the asset if it exists in the Resources folder.

🧠 Conceptual
intermediate
1:30remaining
Why use ScriptableObjects for game data?

Which of the following is the main advantage of using ScriptableObjects to store game data in Unity?

AThey allow data to be shared between multiple game objects without duplication.
BThey automatically serialize private fields without attributes.
CThey replace MonoBehaviour for all scripting needs.
DThey run faster than normal C# classes.
Attempts:
2 left
💡 Hint

Think about how data can be reused and edited in the Unity Editor.

🔧 Debug
advanced
2:00remaining
What error occurs when accessing uninitialized ScriptableObject field?

Given this ScriptableObject class:

[CreateAssetMenu(menuName = "EnemyData")]
public class EnemyData : ScriptableObject {
    public int health;
}

// In some MonoBehaviour:
EnemyData enemy;
Debug.Log(enemy.health);

What error will this code produce at runtime?

APrints 0
BMissingReferenceException
CCompilation error: 'enemy' not assigned
DNullReferenceException
Attempts:
2 left
💡 Hint

Consider what happens if you try to access a field on a null reference.

📝 Syntax
advanced
1:30remaining
Which option correctly defines a ScriptableObject with a string field?

Choose the correct code snippet that defines a ScriptableObject class named ItemData with a public string field itemName and a CreateAssetMenu attribute.

A
public class ItemData : MonoBehaviour {
    [CreateAssetMenu(menuName = "ItemData")]
    public string itemName;
}
B
[CreateAssetMenu(menuName = "ItemData")]
public class ItemData : ScriptableObject {
    public string itemName;
}
C
[CreateAssetMenu(menuName = "ItemData")]
public class ItemData {
    public string itemName;
}
D
[CreateAssetMenu(menuName = "ItemData")]
public struct ItemData : ScriptableObject {
    public string itemName;
}
Attempts:
2 left
💡 Hint

Remember ScriptableObjects must inherit from ScriptableObject class.

🚀 Application
expert
2:30remaining
How many instances of a ScriptableObject exist in this scenario?

You create a ScriptableObject asset named LevelSettings in the Resources folder. In your game, you load it twice using:

var settings1 = Resources.Load<LevelSettings>("LevelSettings");
var settings2 = Resources.Load<LevelSettings>("LevelSettings");

How many separate instances of LevelSettings exist in memory after these calls?

AOne instance shared by both variables
BZero instances, Resources.Load returns null
CTwo separate instances, one per variable
DMultiple instances created each time Resources.Load is called
Attempts:
2 left
💡 Hint

Think about how Unity caches assets loaded from Resources.