- Home /
IEnumerator manipulates variable in android build
Hello, I have created a script which should make a slomotion effect. Therefore, I created a public void which is called on a UI-Button click. This function starts the following iEnumerator with StartCoroutine(Slomotion())
IEnumerator Slomotion()
{
doSlowMo = true;
yield return new WaitForSecondsRealtime(boost.duration);
doSlowMo = false;
}
The strange thing is that this code works in UnityEditor but not on an Android-Build. I debugged the variable "doSlowMo" on the android build and it came out that the variable is changing all the time according to the following pattern:
However, the StartCoroutine method is only called once after the UI event. I tried replacing the WaitForSecondsRealtime function with a while loop but this has the same effect. I´m really confused because the code used to work in a previous build on android, too. Maybe you know an answer to this. Thanks in advance!false, false, true, false, false, true, ...
you are calling multiple times the coroutine or you have multipleobjects with the same script so its getting called multiple times
Actually, I use the script multiple times. Each child of the gameobject "BoostButtons" has a "Button" Component and a "BoostApplier" Component (the essential script). Each Button is calling with the "OnClick" event the method "BoostApplier.OnClick" of its own gameobject. The "OnClick" method is checking which boost it is dealing with and only for the Slomotion-Boost, the Coroutine Slomotion is called. In addition, I´m certain that StartCoroutine is only called once after the button click.
It´s also really interesting that when I add a Debug.Log before and after the yield statement, they are only called once as they should. The variable doSlow$$anonymous$$o is not changed anywhere else than in this coroutine.
so your issue is the var is getting changed but you are never changing its value? thats not posible, the var isnt static right? doslowmo is changing even when you dont call the coroutine?
No, it´s only changing during while WaitForSecondsRealtime is active. The problem is however, that it is not changing once to true but that it is changing every frame like the pattern I described earlier. After the end of the coroutine, everything is fine and the variable is false as it should.
!Update! I have now exchanged the IEnumerator with a counting variable which is changed in Update(). Same effect! No issues in editor, same behaviour in build! I don´t get it.
is not posible to a var change of value just depending where are you deploying the build, the error is somewhere else and without the code we can not help yoou, since the error isnt the coroutine
It's very hard to interpret what you're saying without knowing a) how you're tracking the value and b) how you're starting the coroutine.
And have you put logging at the start of the coroutine so you know how often its getting called?
Answer by RealismWorld · Jun 18, 2019 at 10:24 AM
Fixed it... The problem was that I did a function in Update() which should only be called by one specific boost but was called by every single boost. I´m such a stupid idot! xD Thank you for your effort anyway.
Your answer
Follow this Question
Related Questions
Ienumerator wait for event 0 Answers
How to stop coroutines, when paused 2 Answers
Corountines and messaging system 0 Answers
Can't get past WaitForSeconds in my coroutine 1 Answer
Problem with coroutine 2 Answers