So I’m having an issue yielding coRoutines from coRoutines in my game. First just a touch of background. In my game after a player has scored a point both players then return to their “starting” location, then the puck is inbounded and gameplay starts again. I have a few coRoutines all chaining into one another to get this to work.
When you score a goal is sets off a coRoutine in the gameManager that will update your score, that part works great.
public IEnumerator scoreUpdate (string scoringPlayer, int scoreValue) {
points[scoringPlayer] += scoreValue;
if (points[scoringPlayer] >= scoreMax) {
rounds[scoringPlayer]++;
turnRound();
}
yield return StartCoroutine(resetPlayerPos());
Debug.Log("out of Co");
foreach (KeyValuePair<string, GameObject> player in players) {
if (player.Value.name != scoringPlayer) {
puckToPlayer(player.Value.transform);
}
}
}
After the score is updated I call yield to a coRoutine that should run until all players get back to their starting positions. I’m doing that as follows
IEnumerator resetPlayerPos () {
foreach (characterMotor motor in playerMotors.Values) {
StartCoroutine(motor.moveToStart());
}
foreach (KeyValuePair<string, bool> playerPos in atStartPos) {
while (playerPos.Value == false) {
yield return null;
//Debug.Log(playerPos.Key + " " + playerPos.Value.ToString());
}
}
}
Which is in turn contacting the following coroutine on my player and telling him to move back to his start point.
public IEnumerator moveToStart () {
float progress = 0f;
canMove = false;
gameManager.Instance.atStartPos[gameObject.name] = false;
Vector3 initPos = transform.position;
while (progress < 1) {
transform.position = Vector3.Lerp(initPos, playerStartPos, progress);
progress += Time.deltaTime * resetPosSpeed;
yield return null;
}
gameManager.Instance.atStartPos[gameObject.name] = true;
canMove = true;
Debug.Log(gameObject.name + " move Complete!");
}
Ok so now that I have bored almost everyone out of here with pasted code I can get to the exact issue. The character position reset seems to all be working fine. However the following section of the resetPlayer method in my gameManager never seems to exit.
foreach (KeyValuePair<string, bool> playerPos in atStartPos) {
while (playerPos.Value == false) {
yield return null;
//Debug.Log(playerPos.Key + " " + playerPos.Value.ToString());
}
Which is odd because the coRoutine on the actual player itself should change that value here
gameManager.Instance.atStartPos[gameObject.name] = true;
I’m SUPER confused as to why this isn’t working… And why that coRoutine gets stick