Challenge - 5 Problems
Unity GameObject Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output of this Unity C# code?
Consider this Unity script attached to a GameObject. What will be printed in the Console when the game starts?
Unity
using UnityEngine; public class TestGameObject : MonoBehaviour { void Start() { GameObject obj = new GameObject("MyObject"); Debug.Log(obj.name); } }
Attempts:
2 left
💡 Hint
Look at how the GameObject is created and what name is assigned.
✗ Incorrect
The new GameObject is created with the name "MyObject", so Debug.Log prints that name.
🧠 Conceptual
intermediate2:00remaining
Why does Unity use GameObject as the base for everything visible?
Why does Unity make everything in the scene a GameObject or a component attached to one?
Attempts:
2 left
💡 Hint
Think about how Unity organizes objects and their behaviors.
✗ Incorrect
GameObjects act as containers that hold components like scripts, renderers, and colliders, making it easy to organize and manage objects in the scene.
🔧 Debug
advanced2:00remaining
Identify the error in this Unity script related to GameObjects
What error will this script cause when attached to a GameObject and run?
Unity
using UnityEngine;
public class ErrorTest : MonoBehaviour
{
void Start()
{
GameObject obj = null;
Debug.Log(obj.name);
}
}Attempts:
2 left
💡 Hint
What happens if you try to access a property of a null object?
✗ Incorrect
Since obj is null, trying to access obj.name causes a NullReferenceException at runtime.
🚀 Application
advanced2:00remaining
How to add a component to a GameObject at runtime?
Which code snippet correctly adds a Rigidbody component to a GameObject named "player" during the game?
Unity
GameObject player = GameObject.Find("player");Attempts:
2 left
💡 Hint
Look for the method that adds a new component to a GameObject.
✗ Incorrect
AddComponent() is the correct method to add a component of type T to a GameObject at runtime.
❓ Predict Output
expert2:00remaining
What is the output of this Unity C# code involving GameObjects and components?
Given this script attached to a GameObject, what will be printed in the Console?
Unity
using UnityEngine; public class ComponentTest : MonoBehaviour { void Start() { GameObject obj = new GameObject("TestObj"); var rb = obj.AddComponent<Rigidbody>(); rb.mass = 5f; Debug.Log($"Name: {obj.name}, Mass: {rb.mass}"); } }
Attempts:
2 left
💡 Hint
Check how the Rigidbody component's mass is set before printing.
✗ Incorrect
The Rigidbody component is added and its mass is set to 5, so the output shows the name and mass correctly.