Search Unity

Unity 4.2 yield is not working / bugged?

Discussion in 'Editor & General Support' started by ArmarageX, Aug 2, 2013.

  1. ArmarageX

    ArmarageX

    Joined:
    Aug 5, 2012
    Posts:
    21
    Helloz

    Could i ask if anyone is having any YIELD WAITFORSECONDS problems?

    I have a function called via SENDMESSAGE..., and it doesnt print anything!!

    function Spawn(){
    yield WaitForSeconds(1);
    print("Its working");
    }

    Alternatively i tried this..... but it only works once!!!

    function Spawn(){
    print("Works Once");
    yield WaitForSeconds(1);
    print("Works twice!");
    }

    But it seems to work at some places.... but just this ONE script.... its not working >.<
    Would like to know if anyones experiencing something similar, to confirm it as a bug..... or do i just need to debug harder

    Thanks!
     
    Last edited: Aug 2, 2013
  2. Flavelius

    Flavelius

    Joined:
    Jul 8, 2012
    Posts:
    945
    for me it works( c# ).
    Maybe your sendmessage doesnt arrive correctly. I think theres an overloaded method that prints an error if the receiver is not found.
    Also, i'm not experienced with js, but maybe you need to StartCoroutine there too.
     
    Last edited: Aug 2, 2013
  3. ArmarageX

    ArmarageX

    Joined:
    Aug 5, 2012
    Posts:
    21
    Hmmm i i guess i should have looked into Unity ANSWERS first..... as it is filled with people saying its not working as well...
    Leaving the solution here....
    http://answers.unity3d.com/questions/493046/yield-refuses-to-work-js.html

    I didnt mention that i sent message and then deleted the Sender...

    Apparently... you cannot call tell Object A to call the function at Object B............... and delete Object A....
    Needs to Keep Object A alive..... until the Object B's yield is complete...

    Has it always been like this? Or this some new tech?
     
    Last edited: Aug 2, 2013
  4. Flavelius

    Flavelius

    Joined:
    Jul 8, 2012
    Posts:
    945
    Just a mere idea. Maybe you could try to sendmessage a kind of 'proxy' function which then invokes the real yield function. I dont know if that works but worth a try.

    void InvokeRealFunction() {
    StartCoroutine(RealFunction());
    }
    IEnumerator RealFunction(){
    yield sometime();
    }
     
    Last edited: Aug 2, 2013