- Home /
C# yield in server-side Co-Routine
I am working on an online RPG (I am currently testing it locally, using Unity's Fascilitator and MasterServer exe's) and I run across the following issue when calling a Co-Routine with yield statements at the server-side of the game:
When I call a Co-Routine at the client side everything works smoothly, but when I call it at the server side it runs ok until it reaches the first "yield" statement it finds. Then it stops... Weirdest part is that rarely ( about 1 out of 10 times ) it actually works all the way, as it should >_<
My actions / spells are performed in the following way:
1) At client side: Change a variable of a script
2) Network View synchronizes that variable for the server side
3) At server side: That variable has a get {} property which calls the according action's Co-Routine
Here's one of the Co-Routines:
private IEnumerator EarthRidge (){
.
.
timer = GetCastTime( Action.EarthRidge );
if ((Network.isClient || Network.isServer) && !networkView.isMine )
Debug.Log("CheckPoint: INIT");
.
.
while (timer > 0 ){
if ((Network.isClient || Network.isServer) && !networkView.isMine )
Debug.Log("CheckPoint: LOOP " + timer);
// Update the timer
timer -= Time.deltaTime;
yield return new WaitForEndOfFrame();
// If it's not our client just play through the animation
if ((Network.isClient || Network.isServer) && !networkView.isMine )
continue;
.
.
}
if ((Network.isClient || Network.isServer) && !networkView.isMine )
Debug.Log("CheckPoint: DONE");
.
.
yield break;
}
The Co-Routine reaches "CheckPoint: INIT", it prints the first "CheckPoint: LOOP" and then (usually) doesn't do anything else.. no errors are thrown either.
As mentioned above, it sometimes goes all the way to the end successfully. It has never failed half-way so to speak.. it either fails after the first loop iteration or makes it all the way through..
Any thoughts? Thanks in advance :)