How to use coroutines on a timer within TrueSync?
I'm having trouble getting coroutines to work using the TrueSync package. Here's my code and the error message I'm getting:
I get this error when testing:
I looked into the TrueSyncManager code and it appears the "new WaitForSeconds" parameter type isn't supported. Is there another way TrueSync handles spawning stuff with a timer?
using UnityEngine;
using TrueSync;
using System.Collections;
public class SpawnSystem : TrueSyncBehaviour {
public override void OnSyncedStart() {
StateTracker.AddTracking(this);
TrueSyncManager.SyncedStartCoroutine(SpawnInvoker());
}
private IEnumerator SpawnInvoker() {
while (TrueSyncManager.Players.Count > 0) {
yield return new WaitForSeconds(2);
SpawnPowerup();
}
}
private void SpawnPowerup() {
Debug.LogWarning("Spawned powerup "+TrueSync.TrueSyncManager.Time);
}
I get this error when testing:
ArgumentException: CoroutineScheduler: Unexpected coroutine yield type: UnityEngine.WaitForSeconds
TrueSync.CoroutineScheduler.UpdateCoroutine (TrueSync.CoroutineNode coroutine)
TrueSync.CoroutineScheduler.UpdateAllCoroutines (Int32 frame, FP time)
TrueSync.CoroutineScheduler.UpdateAllCoroutines ()
TrueSync.TrueSyncManager.GenericOnGameCall (System.String callbackName, System.Object[] parameter) (at Assets/TrueSync/Unity/TrueSyncManager.cs:731)
TrueSync.TrueSyncManager.GenericOnGameCall (System.String callbackName) (at Assets/TrueSync/Unity/TrueSyncManager.cs:724)
TrueSync.TrueSyncManager.OnGameEnded () (at Assets/TrueSync/Unity/TrueSyncManager.cs:720)
TrueSync.AbstractLockstep.End ()
TrueSync.AbstractLockstep.EndSimulation ()
TrueSync.TrueSyncManager.EndSimulation () (at Assets/TrueSync/Unity/TrueSyncManager.cs:372)
TrueSync.TrueSyncManager.OnApplicationQuit () (at Assets/TrueSync/Unity/TrueSyncManager.cs:744)
TrueSync.CoroutineScheduler.UpdateCoroutine (TrueSync.CoroutineNode coroutine)
TrueSync.CoroutineScheduler.UpdateAllCoroutines (Int32 frame, FP time)
TrueSync.CoroutineScheduler.UpdateAllCoroutines ()
TrueSync.TrueSyncManager.GenericOnGameCall (System.String callbackName, System.Object[] parameter) (at Assets/TrueSync/Unity/TrueSyncManager.cs:731)
TrueSync.TrueSyncManager.GenericOnGameCall (System.String callbackName) (at Assets/TrueSync/Unity/TrueSyncManager.cs:724)
TrueSync.TrueSyncManager.OnGameEnded () (at Assets/TrueSync/Unity/TrueSyncManager.cs:720)
TrueSync.AbstractLockstep.End ()
TrueSync.AbstractLockstep.EndSimulation ()
TrueSync.TrueSyncManager.EndSimulation () (at Assets/TrueSync/Unity/TrueSyncManager.cs:372)
TrueSync.TrueSyncManager.OnApplicationQuit () (at Assets/TrueSync/Unity/TrueSyncManager.cs:744)
I looked into the TrueSyncManager code and it appears the "new WaitForSeconds" parameter type isn't supported. Is there another way TrueSync handles spawning stuff with a timer?
0
Best Answers
-
Hi @ScriptGeek,
In TrueSync you have to pass time directly in a yield like "yield 3.0f;", it is how we support coroutines for now.5 -
Hi @ScriptGeek, float number will not be a problem in this case if you passed it as a constant like you did and not as a result of float operations (this will lead to undeterrminism). You can use FP as well.5
Answers
-
Hi @ScriptGeek,
In TrueSync you have to pass time directly in a yield like "yield 3.0f;", it is how we support coroutines for now.5 -
@JeffersonHenrique Thanks, I managed to get this working using the line "yield return 3f;"
Using floats doesn't feel deterministic, but if it's synchronized all all clients then I suppose it's good enough for now.0 -
Hi @ScriptGeek, float number will not be a problem in this case if you passed it as a constant like you did and not as a result of float operations (this will lead to undeterrminism). You can use FP as well.5