0
0
Unityframework~20 mins

Instantiating objects at runtime in Unity - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Runtime Instantiator 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 Unity C# code when instantiating a GameObject?

Consider the following Unity C# script attached to an empty GameObject in the scene. What will be printed in the console when the game starts?

Unity
using UnityEngine;

public class InstantiateTest : MonoBehaviour
{
    public GameObject prefab;

    void Start()
    {
        GameObject obj = Instantiate(prefab);
        Debug.Log(obj.name);
    }
}
A"prefab"
B"prefab(Clone)"
C"obj"
DNullReferenceException
Attempts:
2 left
💡 Hint

When you instantiate a prefab in Unity, the new object's name usually has a suffix added.

🧠 Conceptual
intermediate
1:30remaining
Which method is used to instantiate objects at runtime in Unity?

In Unity C#, which method is used to create a copy of a GameObject during runtime?

AGameObject.Copy()
BCreateInstance()
CCloneObject()
DInstantiate()
Attempts:
2 left
💡 Hint

Think about the method that duplicates objects in Unity scripts.

🔧 Debug
advanced
2:00remaining
What error does this code produce when instantiating a prefab without assigning it?

Examine the code below. What error will occur when running this script if the prefab variable is not assigned in the Inspector?

Unity
using UnityEngine;

public class SpawnObject : MonoBehaviour
{
    public GameObject prefab;

    void Start()
    {
        GameObject obj = Instantiate(prefab);
    }
}
ANullReferenceException
BMissingReferenceException
CArgumentNullException
DNo error, object instantiated as empty
Attempts:
2 left
💡 Hint

What happens if you try to use a variable that has not been set?

📝 Syntax
advanced
1:30remaining
Which option correctly instantiates a prefab at a specific position and rotation?

Choose the correct syntax to instantiate a prefab at position (0, 1, 0) with no rotation in Unity C#.

AInstantiate(prefab, new Vector3(0, 1, 0), 0);
BInstantiate(prefab, Vector3(0, 1, 0), Quaternion.identity);
CInstantiate(prefab, new Vector3(0, 1, 0), Quaternion.identity);
DInstantiate(prefab, (0, 1, 0), Quaternion.identity);
Attempts:
2 left
💡 Hint

Remember how to create a Vector3 and use Quaternion for rotation.

🚀 Application
expert
2:30remaining
How many GameObjects are created after running this code snippet?

Given the following Unity C# code, how many GameObjects will exist in the scene after Start() finishes?

Unity
using UnityEngine;

public class MultiInstantiate : MonoBehaviour
{
    public GameObject prefab;

    void Start()
    {
        for (int i = 0; i < 3; i++)
        {
            Instantiate(prefab);
        }
        Instantiate(prefab);
    }
}
A4
B1
C0
D3
Attempts:
2 left
💡 Hint

Count how many times Instantiate is called in total.