• 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
5
Question by Clem · Feb 17, 2011 at 05:51 PM · gameobjecteditorperformanceparent

Reparenting game objects is slow

I have just written an Editor script to reparent game objects and I find that it is performing very poorly.

I am using the following code:

foreach(GameObject obj in gameObjectsToReparent)
{
    obj.transform.parent = newParentGameObject;
}

For 190 game objects the above loop takes an average of 16s. I find it to be rather slow but maybe reparenting a game object involves a lot of work in the background.

Am I doing something stupid in my code? Is this kind of performance to be expected?

Comment
Add comment · Show 3
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 Jesse Anders · Feb 17, 2011 at 08:38 PM 0
Share

Are you saying it takes 16 seconds to reparent ~200 game objects?

avatar image Clem · Feb 18, 2011 at 08:32 AM 0
Share

Yes. What the script does is take all the top level game objects in the scene and move them under a single root. There are about 2000 game objects in the scene and 190 of them are top level game objects.

avatar image antx · Dec 08, 2015 at 08:33 AM 0
Share

I don't know if for editor scripts this is done differently but changeing the parent of an object is normaly done with transform.SetParent();

See: http://docs.unity3d.com/ScriptReference/Transform.SetParent.html

Whether this helps the performance I don't know.

1 Reply

· Add your reply
  • Sort: 
avatar image
7
Best Answer

Answer by Clem · Feb 18, 2011 at 11:54 AM

I got to the bottom of this. Deactivating all the box colliders before reparenting the game objects brings the processing time down to less than two seconds.

Comment
Add comment · 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 immersiveGamer · Nov 22, 2013 at 08:12 PM 0
Share

This helped a ton! I was making a random generator for a map editor I was making. I was trying to do 60 x 60 tiled maps and it was very slow. Just deactivating it before and enabling it after for each object has made it so much faster, I can now do 3600 objects and more with out even breaking a sweat! Tried other physics components and it seems it is only the collides that effects it.

avatar image GLeBaTi · Oct 08, 2014 at 09:56 AM 0
Share

thanks! :)

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 do I get reference to a parent or a child? 2 Answers

How to check parent value instead name value(more details in post) 3 Answers

Destroy Child Object(s) OnValidate? 6 Answers

Unity 5 editor flickering/glitchy (examples inside) 3 Answers

Display Name Above Object 2 Answers


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