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 YoungDeveloper · Nov 23, 2014 at 07:59 PM · updatecount

Does Update() count matter?

As I understand, Update() Gets picked up by reflection on initialization. Would it matter to have one big update, from which everything in game gets updated, or have 100-1000 separate Update() in different scripts. I am talking strictly from optimization and speed perspective, code management or readability is not important here.

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
3
Best Answer

Answer by fafase · Nov 23, 2014 at 08:44 PM

Using one big Update instead of many small ones is, in my opinion, a bad design decision.

You may save a few thousands ticks per frame which is meaningless. On the other hand you lose the point of components.

A class should be doing only what it is meant to do but does it all. Now you want to go for a class that will also take care of all other classes on top of its own purpose. Not only it makes debugging a pain but also it means that your classes are not highly reusable.

The point is that you should design your classes so that you can reuse them with little or no added code. Think of Unity factory components, you drag them and they run, if they would all depend on a big Update, you would always need to use that big update or add some code somewhere. This is where you are heading.

So, my advice, keep everything where it belongs and avoid this God class that is aware of all others and controls them all.

Yes you will save some ticks but you should not consider them over good code.

Comment
Add comment · Show 5 · 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 YoungDeveloper · Nov 23, 2014 at 08:58 PM 0
Share

Thanks, i was asking because i am having problems smoothly updating list of remote players. List is populated by data received from server. The problem is that once level has loaded, it hasn't actually loaded completely and it continues allocation and some asset loading, so it brakes the Update() for all scripts including Remote users. Which basically results seeing a difference in half-one meter, which doesn't sound a lot, but it is. And that amount may and will change depending of machine power running it.

I was thinking to create one single update, which loops through all remote players and updates their movement activities. That would end up me solving the only "laag" problem for that single script.

Other solution would be using ping data or timers, but that's unnecessary traffic data and unparsing which I'd like to to not use.

avatar image fafase · Nov 23, 2014 at 09:14 PM 1
Share

$$anonymous$$ight not be possible but can't you keep all players waiting for all data to be sent?

$$anonymous$$eep a loading screen until all players have finished their coroutine, then you can run:

 private Action UpdateDelegate = ()=>{};
 private bool areReady = false;
 public void SetReady(bool value)
 {
    // Remove Texture
    areReady = true;

   // UpdateDelegate = UpdatePlayer;
 }
 
 void Start(){
     StartCoroutine(Load());
 }
 
 private IEnumerator Load()
 {
    // Loading Texture
    yield return GetData();
    InformServerDataTransfered();
 }

 void Update()
 {
     if(areReady == false)
         return;
     // UpdateDelegate();
 }

InformServerDataTransfered tells the server or the host that this player is done loading, then the server or host checks if all are ready and if so, informs them all with SetReady. The loading texture is removed, the update can start running.

If you don't want to use a a boolean then use a delegate running nothing until it is set to a method when SetReady is called.

avatar image Kiwasi · Nov 23, 2014 at 09:15 PM 1
Share

You did not mention that this was for networking in your OP. Networking has its own set of challenges. Lockstep networking is a plausible solution for dealing with different update rates on different computers.

avatar image YoungDeveloper · Nov 23, 2014 at 09:24 PM 0
Share

Players join in and out dynamically, so there's really no start or end point to start synchronization. Position also isn't sent every frame, only on other client event - input. For each client i request other user list only after OnLevelWasLoaded(), which theoretically should prevent all continuing update from laag. But that's completely misleading, and still takes couple seconds to sober up. In that time player list has been already received, because i expect it to update, but unfortunately. $$anonymous$$aybe that is because i am creating that Update with everything else for the first load. I was thinking to pre-create the update on forever living GO, so it would live and update happily, without any problems. The problem is to get the physical update math to work somewhat good even with scene loads. This is why i had the idea of somewhat "god" updater for all remote players.

avatar image YoungDeveloper · Nov 23, 2014 at 09:47 PM 0
Share

@Bored$$anonymous$$ormon Lockstep networking, very interesting, looks like i will have to use timers.

avatar image
1

Answer by Jeff-Kesselman · Nov 23, 2014 at 09:54 PM

This isn't an answer but comments were closed.

be warned... true lockstep networking behaves VERY badly under situations of significant uneven latency. (AKA the internet)

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 YoungDeveloper · Nov 23, 2014 at 10:02 PM 0
Share

Yes, so another challenge is to create as much seamless transactions so it would not ruin user game experience. The lockstep technique is very interesting, i will look into it! The update problem still stays, i will try separate update method on previously created global GO. Which kind of naive, but it might work, if not, separate thread might do the job.

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

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

Related Questions

How to Update a score count going up and down 1 Answer

How to increment the number by 1's to get distance traveled? 0 Answers

Resource counter doesn't reset on each iteration 0 Answers

How do I Instantiate a prefab to touch and still update a score? 1 Answer

Is there a scene setup call or update for editor scripts? 3 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