How I can convert object to prefab instance?

I duplicated around 100-200 objects and then realized what just could make a prefab… But I have already configured those objects. They all include the same scripts and components. Is there any way to convert all of them to prefab instances?

Yes - just take the object you want to make a prefab, and drag it from the hierachy into the Project folder - a new Asset should appear and you can drag it into your game :slight_smile:

So you want to convert some game objects in your scene into a prefab? Why? What did you mean when you said you had already configured those game objects? What kind of configuring did you apply to each of those objects (scaling, rotating, etc, or changing some properties of some components)? You should only use a prefab when you want to change an object in one place and then apply it to other objects. There’s no built-in way for you to convert all those same objects to a prefab instance, you have to make a script that loops through all of your objects and replace it with your desired prefab (also remember to save the configuring you did on those objects). Here’s an example:

// This is the component that already on your objects that you configured on
public class YourComponent : MonoBehaviour
{
    public int data;
}

[ExecuteInEditMode] // This will make the script run in editor mode
public class ConvertObjectsToPrefab : MonoBehaviour
{
    public GameObject desiredPrefab; // you have to make your desired prefab first and then drag it in here
    public bool stop = false;

    private void Update()
    {
        if (!stop)
        {
            if (desiredPrefab != null)
            {
                // This will find all of your objects with the type YourComponent. This is slow but idk if you have any other ways to find all the objects (does your object have a tag?)
                // You can use GameObject.FindGameObjectsWithTag if your objects use the same tag
                YourComponent[] allObjects = FindObjectsOfType<YourComponent>();

                for (int i = 0; i < allObjects.Length; i++)
                {
                    GameObject instance = Instantiate(desiredPrefab, allObjects_.transform.position, allObjects*.transform.rotation);*_

// This is for saving the changes that you make on each objects
instance.GetComponent().data = allObjects*.data; // if your objects have other scripts and data that you want to save then just do the same*

Destroy(allObjects*.gameObject);*
}
stop = true; // prevent the code to run multiple times
}
}
}
}
Put this script on a game object, then assign the prefab that you want to replace your objects with. It will automatically run. After that, you can just remove the script.