Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 RealismWorld · Jun 16, 2019 at 06:22 PM · coroutineandroid buildeventwaitforsecondsienumerator

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:

false, false, true, false, false, true, ...

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!
Comment
Add comment · Show 15
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 xxmariofer · Jun 17, 2019 at 10:20 AM 0
Share

you are calling multiple times the coroutine or you have multipleobjects with the same script so its getting called multiple times

avatar image RealismWorld · Jun 17, 2019 at 10:43 AM 0
Share

alt text

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.

screenshotslomotion.jpg (66.8 kB)
avatar image RealismWorld · Jun 17, 2019 at 10:57 AM 0
Share

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.

avatar image xxmariofer RealismWorld · Jun 17, 2019 at 12:12 PM 0
Share

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?

avatar image RealismWorld xxmariofer · Jun 17, 2019 at 01:03 PM 0
Share

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.

Show more comments
avatar image RealismWorld · Jun 17, 2019 at 09:03 PM 0
Share

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

avatar image xxmariofer RealismWorld · Jun 17, 2019 at 09:08 PM 0
Share

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

avatar image Bonfire-Boy · Jun 17, 2019 at 11:33 PM 0
Share

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?

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

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.

Comment
Add comment · 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

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

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

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


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