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 Bigproblem01 · Apr 03, 2015 at 04:34 PM · editoriosstuckwhilewhile-loop

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:

  1. startPos = (-1.3, 5.0, 0.0)

  2. endPos = (1.3, -5.3, 0.0)

  3. Candy[Index].transform.position = (1.3, -5.3, 0.0)

  4. candy_LerpTime keeps increasing way past 1 because the loop is stuck

  5. Candy[Index].transform.position.y > postDropPos.y = true

  6. Candy[Index].transform.position.y == postDropPos.y = false

  7. 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

Comment
Add comment · Show 2
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 Owen-Reynolds · Apr 03, 2015 at 06:31 PM 0
Share

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.

avatar image Bigproblem01 · Apr 04, 2015 at 09:42 AM 0
Share

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!

1 Reply

· Add your reply
  • Sort: 
avatar image
0

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.

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 Bigproblem01 · Apr 03, 2015 at 04:53 PM 0
Share

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

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

21 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


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