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 SBull · Sep 15, 2014 at 06:26 PM · javascriptyieldwaitforsecondsfunctionsyield waitforseconds

yield WaitForSeconds preventing further actions.

I have a situation where I am using yield WaitForSeconds in a function and about 50% of the time it works fine and 50% it seems to stop the rest of the function after it from working. I use yield WaitForSeconds in a number of other places in my script and it works just fine. It's only in this function that I'm having the issue with it. Is there something about how it works that I'm not understanding? Here is my current code:

 function OnTriggerEnter (theCollision : Collider)
 {
     if(theCollision.gameObject.tag == "homePoint")
     {
         if(characterHome)
         {
             Deactivate();
             transform.position = homePoint.transform.position;
             Debug.Log("Testing");
 
             yield WaitForSeconds(1);
             Debug.Log("Done waiting");
             homeBox.SendMessage("LoadCharacter");
             homeBox.SendMessage("SetCharacter");
             characterHome = false;
         }
     }
 }



Thanks in advance for any help.

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by KMKxJOEY1 · Sep 15, 2014 at 06:30 PM

Add in a print debug before the yield so you can check that it even gets that far. I have a sneaking suspicion that your yield isn't what's causing your problem.

Comment
Add comment · Show 5 · 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 SBull · Sep 15, 2014 at 06:42 PM 0
Share

I have before. Sorry I forgot to add it in the example code, but that's how I know that the yield is where it is stopping. I'll change it in the example for future reference.

avatar image SBull · Sep 15, 2014 at 07:01 PM 0
Share

I did just notice something odd. When my character touches the homePoint it prints "Testing" twice and "Done waiting" once when it works. But it prints "Testing" and not "Done waiting" at all when it doesn't work. I'm confused as to why this is since the character only touches the homePoint once, but thought it might help figure out why this is happening.

avatar image SBull · Sep 15, 2014 at 07:22 PM 0
Share

Ah. I just figured out why it's printing it twice. I have a character controller and a sphere collider on my character that are different sizes. So one touches the homePoint then an instant after, the other touches it. Unfortunately, I need both of these on my character for different reasons so I'll need to figure out a way around this.

avatar image Kiwasi · Sep 15, 2014 at 08:26 PM 0
Share

For the double collider situation you can add both to GameObjects that are children of your RigidBody. This allows the colliders to function with separate names/tags/layers. They will still all play nicely with the RigidBody.

Once that is done you just implement standard name or tag checking, and only fire the function for one of the colliders.

avatar image SBull · Sep 19, 2014 at 07:15 PM 0
Share

After lots of checking I realized that even though the function is being called twice do to having two colliders on my character, the yield is still the issue. Even if I delete the sphere collider completely to lessen the confusion, the function is stops at the yield. I commented every line of code and even if I set it to "yield WaitForSeconds(0);" or just "yield;" it stops there every time when just the characterController is present.

However simply deleting the yield makes it play through fine (but there is no pause like I need of course). I am truly baffled as to why this is.

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

24 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

Related Questions

yield works, but yield WaitForSeconds does not? 1 Answer

How can I make a variable false for a period of time? 3 Answers

Yield Waitforseconds not working at all 3 Answers

Custom Script and Controls for Canvas UI button ?? 1 Answer

Yield WaitForSeconds doesn't work 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