- Home /
Flash export: "yield return i;" not supported
I've just created a new empty project and created this script.
using System.Collections.Generic;
public class Whatever
{
private IEnumerable<int> Count3()
{
for (int i = 0; i < 3; i++)
yield return i;
}
}
This project cannot be exported to flash. I get an error.
Usage of a type or method not supported by Unity Flash.
Details: Invokes an unsupported method System.Int32 System.Threading.Interlocked::CompareExchange(System.Int32&,System.Int32,System.Int32) on type System.Threading.Interlocked
Source: E:/Unity/EpicFail/Assets/Whatever.cs(�6) at line : 6
Does anyone know why this happens? I use Unity 4.
I got a response from Unity QA a few days later: "as the error states, we do not support such code exportation to flash". I'm not sure how to interpret this. I guess Unity just doesn't support yield returning a value from a method in Flash. I don't use coroutines. Those might specifically work in Flash.
Answer by Owen-Reynolds · Mar 10, 2013 at 05:03 PM
"yield return X" isn't really a legal command. Unity Editor probably guessed what it meant, but Flash refuses. Are you trying to pause for 0+1+2 frames? There's probably a way to rewrite this to be completely legal and look nicer.
Take a look at http://answers.unity3d.com/questions/309320/yield-return-to-wait-for-some-frame-problem.html
No, I'm not trying to pause. This snippet is called from GetEnumerator() of a "fixed length array" of length 3. It is actually a polygon. The 3 values stored in it are the points A, B and C. The real code yields A, B and C ins$$anonymous$$d of i. I don't use this method in my project so I just removed it.
However I might need to implement GetEnumerator() on some other class in the future. This code is one of the things that doesn't work in Flash. It works fine in the Unity web-player though.
The "yield" command pauses, so that loop doesn't belong in GetEnumerator. $$anonymous$$aybe for demo purposes the author added it so you could see it working.
Your answer
Follow this Question
Related Questions
Corutine not behaving like it should? 1 Answer
Add a delay when randomizing a material 0 Answers
IEnumerable in Unity 1 Answer
How can I make a variable false for a period of time? 3 Answers
Coroutines and states 1 Answer