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:

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)


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?

Best Answers

Answers

  • @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.