I am attempting to re-write a lot of my scripts into C#, and I am having issues getting Yield Instructions to function how I wish them to.
No matter how I attempt to execute them, they either cause the methods they are used in to continue to the next method without being finished, or completely crashes Unity on attempt to execute the script.
I have tried:
yield return null;
yield return new WaitForSeconds(0.001f);
yield return new WaitForEndOfFrame();
yield return 0;
yield return StartCoroutine(WaitMethod(0.001f); //This would simply run the WaitForSeconds in another method.
All in locations where I would like to pause temporarily. They mostly cause Unity to just completely freeze.
I do not want to pause very long, for milliseconds just so that Unity can perform as normal, as they are long scripts that take some time to execute.
I know that EVERY method I am attempting these in work normally if they are not yielded at all, but they take too long to execute in one burst and cause them to freeze the game for seconds or more, and because of how often they run it is not acceptable (for example, pathfinding or dynamic generation).
I do not want to create separate Coroutines, as one method relies on the next. The use of the yield functions is simply to pause them for a very short period so that everything else can function.
Any help on this issue would be great. I had these all working in JS, but Yield Instructions in C# seem to work differently so I’m not sure what I’m doing wrong.