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 /
This question was closed May 28, 2012 at 06:49 PM by KiraSensei for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by KiraSensei · May 25, 2012 at 04:02 PM · optimizationmultithreading

Scripts Optimization

Hello everyone !

I would like to know some things about optimization, I already saw a link in another question which gives some tips, but not I'm asking myself...

I was wondering if it is better to have multiple simple scripts, with short Update() methods, or a few scripts but with large Update() methods. by large I mean containing some mathematical algorithms and stuff like that...

And another question which is quite related, Does Unity handle multithreading by its own correctly or does the programmer needs to do things to have a performant work ?

Thanks in advance !

Comment
Add comment · Show 1
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 Fattie · Oct 10, 2013 at 12:12 PM 0
Share

Graham from Unity has answered this question regarding Update()

http://answers.unity3d.com/questions/552765/few-versus-many-update-routines.html

the answer below is a general discussion on performance program$$anonymous$$g

1 Reply

  • Sort: 
avatar image
2
Best Answer

Answer by TowerOfBricks · May 25, 2012 at 04:15 PM

It might be a tiny bit faster to use one large Update method since you will not have the cost of calling the Update function in the other scripts. But that gain would be tiny in comparison, I would NEVER recommend anyone to write large methods just to gain some performance over having many small methods. Unless you are writing high performance code, and the functions are executed a million times per second or something. Optimization is a very large subject, I suggest that you just google a bit on C# Optimization Tutorial, and you will find stuff like this: C# Optimization

A good tutorial, even though I think some optimizations are overkill for game logic code. Just remember: "Premature Optimization Is The Root Of All Evil" (see wikipedia)

Unity will not handle multithreading on it's own. You will have to learn how to do that yourself. From personal experience I can say that, unless you really really have to, or you think piece of code could be speeded up A LOT, multithreading is not worth it since you introduce all kinds of weird possibilities of bugs in places you thought was straight forward. (simply incrementing a variable in two threads at once can cause bugs). Also, you cannot call any part of the Unity API from other threads than the main thread except Debug.Log and probably some math and utility classes (which do not affect the scene or similar).

Comment
Add comment · Show 4 · 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 LawyerOfGod · Jul 18, 2013 at 04:19 PM 0
Share

what i do is to script freely, not worring about performance, when i have finished a scene with all things.. then a gather all the vars that have the same type (for instance Transform), and put all of them inside an array. do it with each var until you have all encapsulated in arrays... but do this only when you have finished the scene (when there is no more to script).

avatar image perchik · Jul 18, 2013 at 04:22 PM 0
Share

LawyerOfGod- that is an absolutely terrible approach. It makes your code completely unreadable, uneditable, and does't save you a whole lot.

avatar image LawyerOfGod · Jul 18, 2013 at 05:06 PM 0
Share

you must to do it when you have all done, when no need to read, when no need to modify, when no need to do anymore... just when you finished all... it saves a lot of processing time... ( i have done this and it works..) is my experience.

avatar image perchik · Jul 18, 2013 at 06:35 PM 0
Share

"Saves a lot of processing time" is debatable and probably the result of some other optimization/cleanup.

In my experience, it is very very very rare that every piece of code in a project dies in that project. It's hardly a rule of thumb. Ins$$anonymous$$d, its a good chance that assets you create in one project will then be used in another one.

Follow this Question

Answers Answers and Comments

8 People are following this question.

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

Related Questions

How to use get a game object's position in multi-thread? 0 Answers

Using multithreading to speed up an algorithm that interacts with components 1 Answer

How can I get the number of physical cores in the CPU (not logical cores) 1 Answer

Setting Material Textures at runtime for the rest of the game 0 Answers

Should i bake the skinned mesh? 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