The easiest way to answer that.... make a test... Code (csharp): Function Start(){ Invoke("MyAnimation", 2.0); Time.timeScale=0.0; } If the Invoke happens, no, if not, yes.
To save anyone else just looking for info and without access to Unity to check the result, Time.timeScale = 0.0f will stop Invokes from being called until it is set to a value other than 0.0f.
To give a more specific answer, Invoke does take time.timeScale into account (it operates on game time, not real time). Test code: Code (csharp): float startTime; void Start() { startTime = Time.realtimeSinceStartup; Invoke("TestMethod", 5.0f); } void TestMethod() { print("Real time taken 1: " + (Time.realtimeSinceStartup - startTime)); startTime = Time.realtimeSinceStartup; Time.timeScale = 0.5f; Invoke("TestMethod2", 5.0f); } void TestMethod2() { print("Real time taken 2: " + (Time.realtimeSinceStartup - startTime)); } takes 5 seconds for the first Invoke, and 10 for the second.
Hey guys, I need Invoke() to be independent from the timeScale, but rather on the real time since startup. Is there any way to make it possible ?
Code (CSharp): public void InvokeRealTime(string name, float duration) { Invoke(name, duration / Time.timeScale); }
Code (CSharp): public void InvokeRealTime(string name, float duration) { Invoke(name, Time.timeScale == 0 ? 0 : duration / Time.timeScale); }
..still, if the timescale changes in the meantime (between the instant when you call Invoke and <duration> seconds later), the waiting time gets screwed up. The only workaround I found is starting a coroutine and performing a realtime wait (checking against Time.realtimeSinceStartup every frame).
it will can a error when Time.timescale is 0, duration / Time.timescale get a infinite value... There has a tween plugin call DoTween ,and it provide a function call DOVirtual.DelayedCall. and you can decide wether ignore timescale or not.. follow is the assetstore link with the document links in the webpage. https://www.assetstore.unity3d.com/en/#!/content/27676
Code (csharp): public void InvokeRealTime(string functionName, float delay) { StartCoroutine(InvokeRealTimeHelper(functionName, delay) ); } private IEnumerator InvokeRealTimeHelper(string functionName, float delay) { float timeElapsed = 0f; while (timeElapsed < delay) { timeElapsed += Time.unscaledDeltaTime; yield return null; } SendMessage(functionName); }
Use coroutine with UnityAction and WaitForSecondsRealtime: Code (csharp): StartCoroutine(InvokeRealtimeCoroutine(DoSomething, seconds)); private IEnumerator InvokeRealtimeCoroutine(UnityAction action, float seconds) { yield return new WaitForSecondsRealtime(_seconds); if (action != null) action(); }
try this: Code (CSharp): public IEnumerator Invoke( System.Action action, float Delay) { yield return new WaitForSecondsRealtime(Delay); if (action != null) action(); }
how come something as basic as this (whether invoke uses game time or real time) doesn't appear in the documentation? https://docs.unity3d.com/ScriptReference/MonoBehaviour.Invoke.html
I agree this should multiply not divide. I do this: InvokeRepeating ("GetServerDateTime", 15 * Time.timeScale, 15 * Time.timeScale); Thanks for the tip on WaitForSecondsRealtime - I have never noticed that!