• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
Question by Azrael · Mar 09, 2010 at 10:17 PM · gameobjecteditorchange

Modifying several gameobjects with an editor script?

How can I change several objects in an scene from one to another? for instance lets suppose I have a ton of spheres and I want to change them all for cubes? and they are different objects? (not the same prefab)

Comment
Joshua

People who like this

1 Show 0
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image

Answer by Azrael · Mar 10, 2010 at 05:15 PM

Ok I finally figured this one by myself, so Im posting the answer for those who may be interested.

Short answer: you cant, You cant replace an object that is already on the scene with another, you can fake it, and get a pretty similar result though.

This is what you need to do

1.-Create a new prefab with the objects you want to "convert" from the scene (the cubes) lets call this "the list" 2.-Create another prefab with the final object you want to replace the originals(the sphere) lets call this "proxy" 3.-Now create an editor script that creates a new proxy in all the positions in the list (you can also copy other details like the script, textures etc)

//Select the list prefab in the assets var SelectedObject:GameObject=Selection.ActiveObject;

//Get the proxy var proxy:GameObject=Resources.Load("Proxy");

//Select all the transform in the list even if they are not active. for (var listObj:Transform in SelectedObject.GetComponentsInChildren(Transform, false){ if (listObj.Transform!=SelectedObject.transform){ Instantiate(proxy,myTransform.position, myTransform.rotation); }}

4.-Delete all the original objects from the scene.

Thats it. Is a bit of a laborious task but is better than modifying all objects by hand (specially if you have 800 like me, dont ask)

I hope someone finds this useful.

Comment
karl_
mihapro
VivienS
Joshua
dogzerx2

People who like this

5 Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image e-bonneville · Apr 07, 2010 at 05:38 PM 0
Share

You might delete all the objects in the scene if they all have something in common by getting them by name or tag and putting them in an array. You can then iterate through the array and kill each one.

avatar image

Answer by KristianHJ · Feb 04, 2012 at 02:15 PM

Just made a blog post about the subject here http://zaxisgames.blogspot.com/2012/02/batch-replace-gameobjects-in-unity.html

Comment
5c4r3cr0w

People who like this

1 Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Bomadeno · Aug 10, 2012 at 08:01 AM 0
Share

If I could upvote you, I would!

avatar image KristianHJ · Aug 10, 2012 at 08:24 AM 0
Share

Np, but great it could help you

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

2 People are following this question.

avatar image avatar image

Related Questions

How would you override Editor object dragging? 0 Answers

Changing gameobject assigned to a variable from string 1 Answer

script help gameobject to playercar 1 Answer

Show prefab/GO in viewport via script 1 Answer

How to change part of complex gameobject instantiated from prefab? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges