Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 TheMightyJ · Jul 26, 2016 at 07:36 AM · fixedupdatefunctionscalls

if Fixed Update calls outside functions

Imagine all variables and custom functions are declared and defined in Awake, but called from within Update, or FixedUpdate for the physics functions.

If my understanding is correct, functions don't do work until they are called, and Unity calls Update and FixedUpdate (and their content) by frame and by time respectively, and it is the priority with which Unity handles them (and their content) that makes FixedUpdate preferable for physics.

So if Update content calls only functions not related to physics, and FixedUpdate content calls only physics functions, why does it matter where the functions are described?

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 tanoshimi · Jul 26, 2016 at 08:03 AM

Your question is somewhat confusing.... it doesn't matter where a function is declared in your script (although you can't declare a function inside another function so your description of declaring a function inside Awake() is incorrect). So you can place the function definition:

 private void MyMethod() { ... }

At the top of your script, underneath Start(), right at the end - it makes no difference. Whatever you do inside MyMethod will only happen when the method is called, which could be:

 void Start() {
   MyMethod();
 }

or:

 void OnMouseClick() {
   MyMethod();
 }

or:

 void FixedUpdate() {
   MyMethod();
 }
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 TheMightyJ · Jul 26, 2016 at 04:52 PM 0
Share

You say functions can't be defined inside other functions, so you recommend Start ins$$anonymous$$d of Awake. But I thought Start and Awake were both functions themselves, so I'm confused about that part of your answer.

But you seem to have understood the point of the question and answered it thus: there is no performance difference between calling a function defined in FixedUpdate, and FixedUpdate calling a function defined elsewhere.

Edit: an explicit confirmation that my understanding is correct would still be appreciated.

avatar image tanoshimi TheMightyJ · Jul 26, 2016 at 09:09 PM 0
Share
  • Start() and Awake() are both functions.

  • I don't recommend Start ins$$anonymous$$d of Awake - they get called at different times and are used for different things. As a rule of thumb, you use Awake to initialise anything related to this gameobject only. You use Start to initialise anything that depends on other gameobjects.

  • There is no performance difference between writing code directly in the body of FixedUpdate, or writing code in a function that gets called from FixedUpdate. I think that's what you're asking.

avatar image TheMightyJ · Jul 27, 2016 at 04:55 PM 0
Share

You said you can't define a function inside another function, so you recommend using Start rather than Awake. But I thought Start and Awake were both functions themselves, so I'm confused by that part of your answer.

But you seemed to get the point of the question and answered it thus: there is no performance difference between calling a function that is defined in FixedUpdate, and FixedUpdate calling a function that is defined elsewhere.

An explicit confirmation that my understanding is correct would still be appreciated.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Is there a way to keep a function from being called until the end of another? 2 Answers

Functions and Rigibodies 1 Answer

how to instantiate an object every second? 2 Answers

What's FixedUpdate 2 Answers

How can I check for a collision before or during FixedUpdate()? 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