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 Zaqnafein · Oct 30, 2013 at 06:55 PM · coroutineyieldfsm

FSM and coroutine problem

Hi,

I am coding a Javascript finite state machine based on and adapted from the C# FSM framework found at the unity wiki. I am trying to add a delay so the animation ends before changing to another state but I obtain the next error:

Assets/Scripts/example.js(192,18 ) BCE0101: Return type 'void' cannot be used on a generator. Did you mean 'IEnumerator'? You can also use 'System.Collections.IEnumerable' or 'object'.

The script es called example and it has all the state class implementations (Idle, Run, Turnaround,...)

Any ideas?

Thanks

 class Turnaround extends FSMState {
     function Turnaround() {
         stateId = StateId.turnaround;
     }
     
     function Reason(player : GameObject) {
         yield player.GetComponent(example).StartCoroutine(player.GetComponent(example).wait(1));
         player.GetComponent(example).SetTransition(Transition.turnaroundIdle);
     }
     
     function Action(player : GameObject) {
         player.GetComponent(example).aniSprite(16, 6, 0, 5, 5, 16);
     }
 }
 
 function wait(waitTime : float) {
     yield WaitForSeconds(waitTime);
     
 }
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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Dave-Carlile · Oct 30, 2013 at 06:59 PM

This looks related:

http://answers.unity3d.com/questions/58242/yield-waitforseconds-causing-compiler-errors.html

Not sure of the why, but it seems that your wait function needs to explicitely return an IEnumerable type, possibly due to it being in a subclass.

So declare your wait function like this:

 function wait(waitTime : float) : IEnumerable
 {
   yield WaitForSeconds(waitTime);
 }
Comment
Add comment · Show 2 · 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 Zaqnafein · Oct 30, 2013 at 11:28 PM 0
Share

Hi Dave, thank you for the interest. I found the related post, but when I declare the return type IEnumerator in wait() and Reason() functions (also in the parent class function) the error disappears but coroutine is never executed!.

avatar image Dracorat · Oct 31, 2013 at 12:03 AM 0
Share

I think it is being executing but you're expecting it to do something after the wait, which isn't specified in that wait method.

Remember that starting a Coroutine is not a "blocking" function. After you start it, the code continues to execute at the next line.

Right now, you wait for 1 second and then ... nothing else happens because nothing else is in the routine.

avatar image
0

Answer by Zaqnafein · Oct 31, 2013 at 12:58 AM

Hi Dracorat, I want to invoke the coroutine wait() and wait until it is completed. After that, I want to execute the next line: (`player.GetComponent(example).SetTransition(Transition.turnaroundIdle`).

Something like the second example of the Script Reference link text. I have add Debug.log("in wait coroutine") in the wait coroutine and the message is never printed...

Thanks in advance

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

17 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

Related Questions

Getting an error when trying to yield 2 Answers

What am I doing wrong with IEnumerator? 1 Answer

Unityscript Coroutine Not Running When Called 1 Answer

Null Reference Exception after updating from 4.0 to 4.1.5 (coroutines) 0 Answers

Last item not being moved (yield problem) 0 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