- Home /
while loop works in editor, stuck on iOS
Hi guys,
I have this piece of code.
candy_currentLerpTime = 0
while(Candy[Index].transform.position.y > postDropPos.y && paused == false)
{
Candy[Index].transform.position = Vector3.Lerp (startPos,
endPos, (candy_LerpTime+=Time.deltaTime));
yield return new WaitForEndOfFrame();
}
in Editor, the while loop moves the Candy
and after it reaches its destination the loop exits.
When I build it on my phone (iOS) the while loop gets stuck
I debugged it while its stuck and this is the output:
startPos = (-1.3, 5.0, 0.0)
endPos = (1.3, -5.3, 0.0)
Candy[Index].transform.position = (1.3, -5.3, 0.0)
candy_LerpTime
keeps increasing way past 1 because the loop is stuckCandy[Index].transform.position.y > postDropPos.y = true
Candy[Index].transform.position.y == postDropPos.y = false
paused = false
Can anyone tell me what's wrong here? How is `Candy[Index].transform.position.y > postDropPos.y = true` when both positions show same coordinates and how come this works in editor but not on the phone???
Thanks
I've had wrong stuff work in Editor, just because of the frame rate difference. The most common is hand-moving something (like you are) which also has a rigidbody I forgot to disable. The lower frame rate just happens to let physics keep it from reaching. Flipping the move and yield might help (currently, the yield gives the object time to move a little.)
I'm not in love with the (candyLerpTime+=...
in the expression. Apple-C probably allows it, but not something I would try.
This is the most sound explanation of what may be going on. I have the game manually locked at 60 FPS just because I need fast and smooth movements and the game is simple/optimized enough for this to be done on iPhone 4 and up so I can get away with it. It's strange however because that Candy has a 2d rigidbody but it is kinematic and thus should not be affected by physics. Besides, I already tried removing the rigidbody altogether before posting here but it didn't help.
I don't know if flipping will help, I'll try that but even if it will, it's a thin line to reline on I guess. I solved this issue by using a hack (while(Candy[Index].transform.position.y > postDropPos.y + 0.1f && paused == false)) but I'd still like to know wtf is going on. If it's as you say though, shouldn't the output of the debugger jump a little back and forth ins$$anonymous$$d of remaining a solid -5.3 all the time (which is exactly the same position i'm checking against)?
Lastly, why don't you like the candyLerpTime
? Imo, this is a much better and proper usage of lerp ins$$anonymous$$d of having a non uniform lerping which takes ages to reach its destination once it's close enough
Thanks for the reply Owen!
Answer by sumeeton · Apr 03, 2015 at 04:42 PM
I hope the code is in a Coroutine. Try using yield return null; instead of yield return new WaitForEndOfFrame();
Edit: That's not even complete code and where is the postDrop transfom position coming from? No clue.
I don't post the whole code to cut out the noise and thus make it easier for you guys to understand. It is a coroutine yes. postDropPos
is a fixed vector that never changes. yield return null results in the same outcome unfortunately.
Your answer
Follow this Question
Related Questions
how to fix the "unityexception : launching ios project via xcode failed" exception ? 0 Answers
Removing unneeded shaders Shader Unsupported Hidden/VR/BlitCopyFromTexArray 0 Answers
Unity 2018.2.21 iOS Build Stuck in xCode 1 Answer
Editor Stuck at "UnitySynchronization.ExecuteTasks" 1 Answer
or doesn't work in while loops? 1 Answer