Prefab instance
- Game Development course
- Intermediate
- Lesson 51/83
- 4 min
Learn to add a prefab to the scene as an instance.
What Is a Prefab Instance?
When you drag a Prefab asset from the Project window into a scene, Unity creates an instance connected to that asset. An instance is a Prefab example that can be edited in the scene. You can create multiple instances from the same Prefab asset.
// Prefab Asset
// Scene Instance A
// Scene Instance BEditing an Instance
You can change properties such as position, rotation, or scale on a Prefab instance in the scene. These changes can be stored as overrides on the instance. The Overrides menu in the Inspector helps you manage differences between the source and the instance.
// Position Override
// Rotation Override
// Scale OverridePractice Work with a Prefab Instance
Use an assigned Prefab instance reference from the Inspector to change the object's name. If the reference is not empty, set its new name to ActiveCrate and print the result to the console.
Starter code
using UnityEngine;
public class InstanceEditor : MonoBehaviour
{
public GameObject crateInstance;
void Start()
{
}
}Sample solution
using UnityEngine;
public class InstanceEditor : MonoBehaviour
{
public GameObject crateInstance;
void Start()
{
if (crateInstance != null)
{
crateInstance.name = "ActiveCrate";
Debug.Log("Instance adı: " + crateInstance.name);
}
}
}Expected output
Instance adı: ActiveCrate
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 What is created when you drag a Prefab asset from the Project window into a scene?
- Physics Material
- Prefab Instance Correct answer
- A new Script file
- Animator Controller
Explanation: A Prefab asset added to a scene creates a Prefab Instance.
2 A Prefab Example in the Scene
Sahneye eklenen ve kaynak Prefab assetine bağlı olan nesneye Prefab ____ denir.
Sahneye eklenen ve kaynak Prefab assetine bağlı olan nesneye Prefab Instance denir.
Explanation: A Prefab Instance is an example in the scene connected to its source Prefab.
3 Match Instance Properties
| Term | Meaning |
|---|---|
Prefab Asset |
The source stored in the Project window |
Instance |
A Prefab example used in a scene |
Override |
Instance difference from the source |
Overrides Menu |
Area for viewing and managing changes |