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
1
Question by theUndeadEmo · Dec 16, 2012 at 07:23 PM · updateefficiency

Having lots of Update Functions

is it bad practice (too costly) to use lots of update functions across the game world. or does it not matter a lot

thanks

Comment
Add comment
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
5
Best Answer

Answer by asafsitner · Dec 16, 2012 at 08:58 PM

Obviously Unity is designed around the idea of Update (and the other event methods like OnGUI or Start), but it's also obvious that having many events can hurt performance. My advice is: If you don't need something, don't have it there. If the component doesn't have code inside it's Update method, remove it.

Other than that, if you have an extremely high number of things that happen in our game, you should ask yourself if they all need to happen every frame, and if not, implement your own "job scheduler" (by the way using coroutines to do that for you can cause even greater performance impact than just using Update, depending on the number of coroutines you have and what they do exactly) or some other manager of that sort.

I've been using quite a lot of Update calls myself (>2000) and the call itself was not the bottleneck.

Comment
Add comment · Show 3 · 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 clunk47 · Dec 16, 2012 at 09:08 PM 0
Share

Accept this answer. I gave +1.

avatar image fafase · Dec 16, 2012 at 09:11 PM 1
Share

The call itself is a question of few cycles so it is nothing. As mentioned by @asafsitner, it is what is inside that matters.

avatar image Eric5h5 · Dec 16, 2012 at 09:23 PM 0
Share

The overhead for individual Update calls does actually add up to a noticeable amount with a lot of objects.

avatar image
0

Answer by Eric5h5 · Dec 16, 2012 at 09:22 PM

A call to Update has overhead, so if you have 1000 objects with Update, then you have that overhead X 1000. If you have a lot of objects that do need updating every frame, it would be more efficient to have a single Update function that uses a loop to iterate though the objects and performs the necessary operations for each one inside the loop.

Comment
Add comment · 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 asafsitner · Dec 16, 2012 at 09:26 PM 0
Share

Agreed 100%.

But, as I said, you'd have to identify the bottleneck in your game. In my case it wasn't the overhead, but rather the code (and Camera.Render which took ~20ms in itself...)

As a side note, in earlier versions of Unity the overhead to calling OnGUI (even an empty method) was tremendous, even if it was only called once. I haven't used GUI as heavily since, but from what I've heard it should have been fixed (i.e. it's still terrible but much better than before).

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

13 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

Related Questions

Efficiency of Game Loops 2 Answers

How to code input. 1 Answer

How would i change this string in update to a StringBuilder? 2 Answers

Do something when health is below X 2 Answers

Setting Text.text in UI efficiency? 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