Search Unity

yield statment

Discussion in 'Scripting' started by Harry Tuttle, Aug 1, 2007.

  1. Harry Tuttle

    Harry Tuttle

    Joined:
    Jan 3, 2006
    Posts:
    122
    I'm trying the MeshSerializer package from the Unity Wiki and it's failing because it's trying to access data that hasn't been downloaded yet.

    Looking at the code I can see there should be a yield statement in there:

    Code (csharp):
    1.  
    2. static function ReadMeshFromUrl( url : String ) : Mesh
    3. {
    4.     var download = WWW(url);
    5.     yield download;
    6.     if( download.error )
    7.     {
    8.         print ("Error downloading mesh from " + url);
    9.         return null;
    10.     }
    11.    
    12.     var data = download.data;
    13.  
    However when this is compiled I get a :
    error BCE0101: The return type of a generator must be either 'System.Collections.IEnumerable' or 'Object'.

    My code matched the use of yield in the Unity documentation example - what am I doing wrong?
     
  2. Jonathan Czeck

    Jonathan Czeck

    Joined:
    Mar 17, 2005
    Posts:
    1,713
    I believe due to the way coroutines work internally, you can't make them a static method. Try removing "static" and making that class a singleton.

    It would be great to file a bug on this so at the very least a better compiler error message can be given.

    Cheers,
    -Jon
     
  3. Harry Tuttle

    Harry Tuttle

    Joined:
    Jan 3, 2006
    Posts:
    122
    That's solved the problem, thank you for your help.