Prefabutility



Author: Matthew Miner (matthew@matthewminer.com)

Adds a prefab data cleaner window under Window/Prefab data cleaner. Place the scripts in a folder named Editor in your project's Assets folder.; Open the window by selecting Window/Prefab data cleaner.; What it does.

I'm designing a racing game for my graduation project. I used PrefabUtility.SaveAsPrefabAsset to save my color change on the car prefabs, I finished the codes and it work well in Unity, but when I want to build my project,the Unity give me a error:The name 'PrefabUtility' does not exist in the current context. (GameObject)PrefabUtility.InstantiatePrefab (prefab); because Instantiate doesn't keep the link to the prefab but creates a clone. So the above code works great so far and the object is inserted to the scene as if I would drag and drop it. Now I would like to change this newly instantiated objects parent to parent so I added the line.

Load

Description

Creates a prefab containing the contents of the currently selected game object.

Unity

Usage

Place the script inside the Editor folder. Select a GameObject and choose 'GameObject > Create Prefab From Selection'. A new prefab will be created in the root directory bearing the same name as the GameObject.

Faults:

To Do

  • Currently the script replaces any existing prefab with the same name; more desirable would be to append a number to the filename of the new prefab
  • The selected GameObject should become an instance of the newly created prefab

C# - CreatePrefabFromSelected.cs

UnityPrefabutility.instantiateprefab

C# - Updated CreatePrefabFromSelected.cs

I decided to update this script in can anybody is intewrested. It now will give a popup if the prefab already exits and you can choose to overwrite the prefab or cancel. It also replaces the selected gameObject with the new prefab.

  • Cameron Bonde

- Updated to accept multiple selected objects and not use /prefabs folder (without it it deletes the GO without creating prefab)

Prefabutility

- Fixed the script to make sure the new object have the same parent as the old one in the scene. --Blikstad 06:11, 20 May 2012 (PDT)

- Extended with choice of save folder by winxalex

C# - CreatePrefabFromSelected.cs Procedural Mesh Version

Unity Find Prefab

Small update for procedural mesh creations: it saves the created mesh to disk and inside a prefab, instead of losing it, and keeps all prefab size, shader, collider, and script settings in 1 prefab.

Requires that you have a folder called Assets/savedMesh

Prefabutility.instantiateprefab Vs Instantiate


Prefabutility Saveasprefabasset

Retrieved from 'http://wiki.unity3d.com/index.php?title=CreatePrefabFromSelected&oldid=18980'