• 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 JasonBricco · Jun 05, 2014 at 06:02 AM · c#performancereflectioneventsupdate function

Regarding Update() Performance

Hi all,

I've done a lot of research about Update() and the performance of it. And from what I can tell, it's not great. But I'm a little confused about why that is. I've seen information that almost tells me what I want to know, but not quite.

Is it slow because it runs every single frame? Or is there more to it than that? From what I understand, there's some slow-ish reflection happening to figure out that you defined the Update method in your script.

But does that reflection happen once at the start, then after that it's pretty much directly calling a function every frame? Or is there a significant overhead every single frame with Update(), that you wouldn't get if you did it say...

Make one update function that fires off an event, to which everything else that would have an update function subscribes to. That way you have one update function firing off an event each frame and then each script that hooks into that has a kind of update function through that event, without defining it directly.

Would that be faster than putting Update() all over, or would it be about the same?

Thanks in advance.

Comment
Add comment · Show 8
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 robertbu · Jun 05, 2014 at 06:50 AM 2
Share

Should be quick to test.

avatar image JasonBricco · Jun 05, 2014 at 06:55 AM 0
Share

Sure, but that would take a bunch of time that I could spend doing other things... and furthermore, it wouldn't help other people who might want to know the same information.

Oh well. I'll end up testing it tomorrow if no one provides an answer (going to sleep for now).

avatar image rutter · Jun 05, 2014 at 07:21 AM 0
Share

If your Update calls are slowing down a game, it's more likely that the problem is with whatever you're doing in those Update functions.

Put another way: Unity is not always the most efficient engine, but you have to be pretty serious about optimization to do better.

avatar image rutter · Jun 05, 2014 at 07:32 AM 1
Share

Unity can make use of reflection and other less-than-performant methods, sometimes, but it usually doesn't do so per-frame.

I wouldn't be surprised if a homebrewed Update routine ends up saving CPU time, but it would have other problems. The memory required to keep all of those object references will end up being non-trivial, and besides that it'll be on top of whatever memory Unity is already allocating for that purpose. It's easy to get caught up in algorithm analysis without considering the space/time tradeoffs in certain methods.

Or, put another way: if your own method uses a lot of memory, even though it seem academically faster, it may degrade memory cache performance and end up slower in practice.

In my experience, memory allocation tends to be a bigger problem than CPU use. Unless you're doing awesome stuff like traversing the scene graph ten times per frame.

I have sometimes written my own Update routines when I need more control over my components than Unity gives me out of the box.

avatar image robertbu · Jun 05, 2014 at 07:47 AM 2
Share

I ran a quick and dirty test. It took about 15 $$anonymous$$utes to setup. I used empty game objects that are repositioned each frame. Using a PC build (don't do tests in the editor), the app first slowed down at 55,000 game objects. With a centralized Update() (no script on the game objects), it first slowed down at 90,000 game objects.

Of course you'll want to run a test on the specific platform you will be using. Results may be different for different platforms and different setups.

Show more comments

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.

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

23 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Distribute terrain in zones 3 Answers

Question about unsubscribing eventhandlers OnDisable and OnEnable 2 Answers

Multiple Cars not working 1 Answer

Multiple UPDATE functions running simultaneously? 2 Answers

Renderer on object disabled after level reload 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