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 united4life · Mar 29, 2013 at 09:53 AM · update

How to call a function in update only once?

I tried the bool, int and playerprefs method for calling only once, which are working fine. Is there any other way other than these methods?

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

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Maulik2208 · Mar 29, 2013 at 10:21 AM

if you want to use the function only once then Update is not your thing dude ......because update is called at every frame and now lets come back to your question and i think you have already suggested almost possible ways to do it anyway......cheers from INDIA......

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 whydoidoit · Mar 29, 2013 at 11:08 AM 0
Share

I agree, don't clutter your Update function with single time tests - that's what coroutines are for. They make you code easier to read and they take less time to accomplish what you are looking for.

avatar image
0

Answer by sparkzbarca · Mar 29, 2013 at 10:49 AM

Bool is probably the best method.

The issue is hardly anything is faster than checking if a value is equal to 1 or not. Since you'd need to set up a check to see if you should run it you want to quickest check which is basically a true/false test.

Even if there are other methods they aren't as good (at least not likely)

bool is very clear and concise which is great for code. it reads well. Also its very fast also a great plus.

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 united4life · Mar 30, 2013 at 09:31 AM 0
Share

Yeah i agree bool is the best method but somehow i feel that is not a proper way of coding. That is the reason i asked this question. If there is no other method i have to go with bool method

avatar image
0

Answer by united4life · Mar 29, 2013 at 12:17 PM

Thanks for your replies. I will use bool only as this is the best way.

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 whydoidoit · Mar 29, 2013 at 12:18 PM 0
Share

No it really isn't:

  • Cluttered code

  • Slower than a coroutine

avatar image Maulik2208 · Mar 29, 2013 at 12:33 PM 0
Share

is there any specific reasons behind calling the function once in Update ????? Common man it's not a good choice but after all it's your matter and you can suit your self ......... Cheers from INDIA.....have a happy coding.......

avatar image united4life · Mar 30, 2013 at 09:28 AM 0
Share

there is no specific reason in update. Its just that i cannot use it in start coz every time a action happens i have to check which should be in update. I hope I am not wrong. I know it is not a good choice so if u know any other method please let me know. I will try Startcoroutine also.... .Cheers!!!!

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

13 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

Related Questions

A node in a childnode? 1 Answer

Can't update Unity to 3.5.5f3 1 Answer

Support for Delta Updates in Unity 1 Answer

Unity 4.6: GetComponent().onClick... how do you add an event to button click? 6 Answers

Unity 4.0.1f2 update and script,fbx file errors,. 0 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