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 stevesan · Dec 22, 2011 at 02:35 AM · physicstriggerseventscollisionsupdates

Clarification on updates, physics events order and frequency?

Is there a summary clarifying when, how often, and in what order all the following MonoBehaviour messages are triggered: Update, FixedUpdate, OnCollisionEnter (and all other col/trigger events)? I could probably figure it out by trial and error, but could someone point me to a doc that clarifies all this stuff? Cheers.

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

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by aldonaletto · Dec 22, 2011 at 08:27 AM

Unity has two main "cycles" running independently: the update cycle and the physics cycle (see Scripting Overview). The update cycle is synced to the frame rate: before rendering each frame, Unity first calls all Update functions in all scripts, then calls all LateUpdate functions. Other functions that are called in the update cycle are the camera events (OnPreCull, OnPreRender etc.). Coroutines are also tied to the update cycle: when an yield is executed, the coroutine is suspended, and will resume in the next update cycle (not sure if before or after Update).
The physics cycle is where all physics related stuff happens (physics calculation and collision detection); it has a "fixed" rate set in the Time Manager - 50 times per second by default (20mS). Unity tries to keep this rate, but some extremely long Update may disturb this. The function FixedUpdate is called in all scripts during the physics cycle, as well as all the collision/trigger events. From my experience, collision/trigger events seem to be called after the FixedUpdates, but I have not extensively tested this.
Besides these two main cycles, Unity has also the "GUI cycle": the function OnGUI is called before rendering the GUI elements and every time a system input event (key, button, mouse) is reported. The GUI cycle may thus happen multiple times during one single update cycle.
As a rule of thumb, all Input.WhateverDown/Up functions (GetKeyDown, GetButtonUp etc.) must be called only in the update cycle (Update, LateUpdate). When a key is pressed, for instance, GetKeyDown returns true for the whole update cycle; if called inside OnGUI (a common error) it may return true several times.

Comment
Add comment · 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

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Can't get OnTriggerEnter to work 1 Answer

Ignore collisions with self but still trigger with self 2 Answers

How to make events only trigger for specific object? 0 Answers

Detecting Input on ~100 Objects 2 Answers

Apply rigid body force in opposite direction of collider 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