- Home /
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?
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......
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.
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.
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
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.
No it really isn't:
Cluttered code
Slower than a coroutine
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.......
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!!!!