Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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
0
Question by vitaly mind · Oct 19, 2013 at 05:53 PM · gameobjectcpucpu usage

Adding GameObject № 1 and GameObject № 10000 is different in CPU cost, why?

Dear Unity,

I noticed strange (at least for me) behaviour of unity. I would like ask if anyone can explain it.

Consider following code: Note that this code attached to empty GameObject as only component. Also there nothing else in this scene, it is completely empty.

 using UnityEngine;
 using System.Collections;
 
 public class NewBehaviourScript : MonoBehaviour 
 {
     private int count = 0;
     void Update () 
     {
         if(Input.GetMouseButton(0))
         {
             count++;
             GameObject test = new GameObject("test");
         }
         if(Input.GetMouseButton(1))
         {
             Debug.Log(count);
         }
     }
 }

This code adds new empty GameObject each frame while mouse button is held (incrementing int is for counting purposes).

The interesting thing is that, when adding ONE and first GameObject a fraction of CPU power is used.

But, when adding ONE GameObject to existent 10000 of GameObject much more CPU power is used for adding the same ONE GameObject.

NOTE: If you have problem in achiving such a result, it means you have a better CPU than me. Though, try adding more than ONE GameObject at once using this code:

 ...
 GameObject test = new GameObject("test");
 GameObject test1 = new GameObject("test");
 GameObject test2 = new GameObject("test");
 GameObject test3 = new GameObject("test");
 ...

If you will patiently hold mouse button for some time you will soon notice, ever growing CPU load, while amount of work is, on first sight, constant.

Now if you release button, CPU usage emmidietly fall to normal amount. Though if button pushed again, CPU will be loaded again back to same value. Eventually it will be loaded 100% instantly.

No matter how much GameObjects specific CPU can handle, but rule that every new GameObject consumes more CPU time to be created than previous is consistant.

Also it is remarkable that Unity running smoothly even with some 100 000`s (hundred thousands) empty GameObjects in scene, but if you were to add ONE more it will cause a huge freeze even on top rigs. Any idea why?

Please correct me if i put something wrong or miss cruel aspect.

Comment
Add comment · Show 2
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 fafase · Oct 19, 2013 at 05:56 PM 0
Share

Reason I could see, when starting you have free memory, after 10000 objects the memory may need to look for empty space. This seems even more probable since as you go, you tend to say the time increases. Just an assumption.

avatar image Benproductions1 · Oct 19, 2013 at 10:34 PM 0
Share

Have you tried this in a build? Sometimes the Unity Editor is a little special in it's performance with certain tasks.

0 Replies

· Add your reply
  • Sort: 

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.

Follow this Question

Answers Answers and Comments

15 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Android app doesn't use GPU. Why? 0 Answers

Hardware usage for VideoPlayer 0 Answers

High CPU Usage on GFX.processcommands 1 Answer

Does using Mesh Collider use up more CPU verses just a box Collider? 1 Answer

Why is Unity not using all the power available? 0 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