This page describes the supported features when running the Unity Editor and Standalone Player in batch mode.
When running Unity, the following built-in coroutine operators add functionality:
The following table shows which of these operators Unity supports inside the Editor and Standalone Player, and when running each of them in batch mode using the -batchmode command line argument:
Editor | Editor -batchmode | Unity Standalone Player | Unity Standalone Player -batchmode | |
---|---|---|---|---|
AsyncOperation |
Yes | Yes | Yes | Yes |
WaitForEndOfFrame |
Yes | No* | Yes | Yes |
WaitForFixedUpdate |
Yes | Yes | Yes | Yes |
WaitForSeconds |
Yes | Yes | Yes | Yes |
WaitForSecondsRealtime |
Yes | Yes | Yes | Yes |
WaitUntil |
Yes | Yes | Yes | Yes |
WaitWhile |
Yes | Yes | Yes | Yes |
* You cannot use WaitForEndOfFrame
when running the Editor with -batchmode
, because systems like animation, physics and timeline might not work correctly in the Editor. This is because Unity does not currently update these systems when using WaitForEndOfFrame
.
In the Editor, press the “Play” button to run your code with coroutines.
To run coroutines when launching the Editor in batch mode from the command line, enter:
C:\Program Files\Unity\Editor\Unity.exe -projectPath PROJECT_PATH -batchMode
Launch your Standalone Player to run your code. The Player loads and then waits for your coroutines to complete.
To run coroutines when launching the Player in batch mode from the command line, enter:
PATH_TO_STANDALONE_BUILD -projectPath PROJECT_PATH -batchMode
For example, on Windows:
C:\projects\myproject\builds\myproject.exe -batchMode
On Mac:
~/UnityProjects/myproject/builds/myproject -batchMode
using System.Collections;
using UnityEngine;
[ExecuteInEditMode]
public class ExampleClass : MonoBehaviour
{
public void Start()
{
StartCoroutine(Example_AsyncTests());
}
public IEnumerator Example_AsyncTests()
{
Debug.Log("Start of AsyncLoad Example");
var load = UnityEngine.Resources.LoadAsync("");
yield return load;
yield return null;
Debug.Log("End of AsyncLoad Example");
}
}
using System.Collections;
using UnityEngine;
[ExecuteInEditMode]
public class ExampleClass : MonoBehaviour
{
public void Start()
{
StartCoroutine(Example_WaitForEndOfFrame_Coroutine());
}
public IEnumerator Example_WaitForEndOfFrame_Coroutine()
{
Debug.Log("Start of WaitForEndOfFrame Example");
yield return new WaitForEndOfFrame();
Debug.Log("End of WaitForEndOfFrame Example");
}
}
using System.Collections;
using UnityEngine;
[ExecuteInEditMode]
public class ExampleClass : MonoBehaviour
{
public void Start()
{
StartCoroutine(Example_WaitForFixedUpdate_Coroutine());
}
public IEnumerator Example_WaitForFixedUpdate_Coroutine()
{
Debug.Log("Start of WaitForFixedUpdate Example");
yield return new WaitForFixedUpdate();
Debug.Log("End of WaitForFixedUpdate Example");
}
}
using System.Collections;
using UnityEngine;
[ExecuteInEditMode]
public class ExampleClass : MonoBehaviour
{
public void Start()
{
StartCoroutine(Example_WaitForSeconds_Coroutine());
}
public IEnumerator Example_WaitForSeconds_Coroutine()
{
Debug.Log("Start of WaitForSeconds Example");
yield return new WaitForSeconds(1.5f);
Debug.Log("End of WaitForSeconds Example");
}
}
using System.Collections;
using UnityEngine;
[ExecuteInEditMode]
public class ExampleClass : MonoBehaviour
{
public void Start()
{
StartCoroutine(Example_WaitForSecondsRealtime_Coroutine());
}
public IEnumerator Example_WaitForSecondsRealtime_Coroutine()
{
Debug.Log("Start of WaitForSecondsRealtime Example");
yield return new WaitForSecondsRealtime(1.5f);
Debug.Log("End of WaitForSecondsRealtime Example");
}
}
using System.Collections;
using UnityEngine;
[ExecuteInEditMode]
public class ExampleClass : MonoBehaviour
{
public void Start()
{
StartCoroutine(Example_WaitUntil_Coroutine());
}
public IEnumerator Example_WaitUntil_Coroutine()
{
Debug.Log("Start of WaitUntil Example");
yield return new WaitUntil(() => Time.time > 5.0f);
Debug.Log("End of WaitUntil Example");
}
}
using System.Collections;
using UnityEngine;
[ExecuteInEditMode]
public class ExampleClass : MonoBehaviour
{
public void Start()
{
StartCoroutine(Example_WaitWhile_Coroutine());
}
public IEnumerator Example_WaitWhile_Coroutine()
{
Debug.Log("Start of WaitWhile Example");
yield return new WaitWhile(() => Time.time < 5.0f);
Debug.Log("End of WaitWhile Example");
}
}
2018–06–06 Page published
Added advice on using batchmode and coroutines in 2017.4
When you visit any website, it may store or retrieve information on your browser, mostly in the form of cookies. This information might be about you, your preferences or your device and is mostly used to make the site work as you expect it to. The information does not usually directly identify you, but it can give you a more personalized web experience. Because we respect your right to privacy, you can choose not to allow some types of cookies. Click on the different category headings to find out more and change our default settings. However, blocking some types of cookies may impact your experience of the site and the services we are able to offer.
More information
These cookies enable the website to provide enhanced functionality and personalisation. They may be set by us or by third party providers whose services we have added to our pages. If you do not allow these cookies then some or all of these services may not function properly.
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us to know which pages are the most and least popular and see how visitors move around the site. All information these cookies collect is aggregated and therefore anonymous. If you do not allow these cookies we will not know when you have visited our site, and will not be able to monitor its performance.
These cookies may be set through our site by our advertising partners. They may be used by those companies to build a profile of your interests and show you relevant adverts on other sites. They do not store directly personal information, but are based on uniquely identifying your browser and internet device. If you do not allow these cookies, you will experience less targeted advertising. Some 3rd party video providers do not allow video views without targeting cookies. If you are experiencing difficulty viewing a video, you will need to set your cookie preferences for targeting to yes if you wish to view videos from these providers. Unity does not control this.
These cookies are necessary for the website to function and cannot be switched off in our systems. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms. You can set your browser to block or alert you about these cookies, but some parts of the site will not then work. These cookies do not store any personally identifiable information.