C# Script must be placed in "editor" folder.
using UnityEngine; using UnityEditor; using System.Collections; public class ReplaceGameObjects : ScriptableWizard { public bool copyValues = true; public GameObject NewType; public GameObject[] OldObjects; [MenuItem("Custom/Replace GameObjects")] static void CreateWizard() { ScriptableWizard.DisplayWizard("Replace GameObjects", typeof(ReplaceGameObjects), "Replace"); } void OnWizardCreate() { foreach (GameObject go in OldObjects) { GameObject newObject; newObject = (GameObject)EditorUtility.InstantiatePrefab(NewType); newObject.transform.position = go.transform.position; newObject.transform.rotation = go.transform.rotation; newObject.transform.parent = go.transform.parent; DestroyImmediate(go); } } }
Here's a visual walkthrough:
Go into Custom ->Replace Gameobjects
Select any number of gameobjects and drag them into "Old Objects".
Then, from the project pane, drag the gameobject that you want to replace with into "New Type".
Press "Replace"
Enjoy :)
/Kristian
And credits to Michael L. Croswell
Thanks for the script, very handy! You might want to mention that this should be a .cs script and that the script needs the following at the top for it to work:
ReplyDeleteusing UnityEngine;
using UnityEditor;
using System.Collections;
Thanks again!
Hi Timzilla
ReplyDeleteTrue, thanks for the feedback.
Correction has been made.
Thanks for sharing this! It pays off even when replacing a single object (because of the transform preservation). Awesome!
ReplyDeleteNo problem
DeleteGlad it could help you
newObject.transform.parent = go.transform.parent;
ReplyDeleteWill go wrong i guess if 'go' is also an object to be replaced?
Say A and B will be replaced but B is also a parent of A.
Then A.parent will reference a null object after the script has run.
Thank you very much! This is quite a time saver. I wish I found this a lot sooner.
ReplyDeleteNp, glad you found it helpful
DeleteThanks mate you saved me a lot of time =)
ReplyDelete