To improve usability and performance, Unity might change the way classes, functions and properties (the API) work. Occasionally, these improvements might introduce breaking changes when moving from one major Unity version to another.
To minimize the impact of breaking changes, the API updater identifies and updates obsolete code in your scriptsA piece of code that allows you to create your own Components, trigger game events, modify Component properties over time and respond to user input in any way you like. More info
See in Glossary and assemblies.
The API updater consists of the ScriptUpdater and the AssemblyUpdater, which are responsible for updating source code (scripts) and assemblies (dll files) respectively.
Note: The API Updater can only fix certain errors and warnings in the API. These are indicated as UnityUpgradable in the console message. You must manually resolve other errors or warnings that the API Updater cannot handle.
When a script compilation is triggered, the API updater runs automatically. For example, this occurs when you:
The API updater offers to update any obsolete code that it detects. If you accept, it rewrites any obsolete code with the recommended updated version of the API.
For example, the API updater would convert the following obsolete statement from:
light.color = Color.red;
to:
GetComponent<Light>().color = Color.red;
The steps below describe the workflow of the API updater when Unity triggers a script compilation:
The updater can run multiple times if scripts with obsolete code fall into different compilation passes, for example, editor scripts.
If you don’t allow the API updater to update your scripts, the console displays any script errors or warnings. Errors or warnings which the API updater could resolve display (UnityUpgradable) in the message.
If your script has other errors which prevent the API updater from running successfully, the Console displays a message to inform you of this. You must resolve those errors before the API Updater can complete the updates.
When running Unity in batch mode from the command line, use the -accept-apiupdate
option to run the API updater. For more information, see Command Line Arguments.
The API updater logs changes it makes to any assemblies to the Editor log. To control how much information is logged, set the UNITY_APIUPDATER_LOG_THRESHOLD environment variable to the desired log threshold and start Unity. For example:
On Windows:
c:> set UNITY_APIUPDATER_LOG_THRESHOLD=Debug
c:> \path\to\unity\Unity.exe
On Linux:
$ export UNITY_APIUPDATER_LOG_THRESHOLD=Debug
$ /path/to/unity/Unity
On Mac:
$ export UNITY_APIUPDATER_LOG_THRESHOLD=Debug
$ /path/to/unity/Unity
Note: You can also use version controlA system for managing file changes. You can use Unity in conjunction with most common version control tools, including Perforce, Git, Mercurial and PlasticSCM. More info
See in Glossary
to see changes the API updater makes to a project’s scripts.
When AssemblyUpdater has finished, the Editor.log displays the changes. For example:
[AssemblyUpdater] Property access to 'UnityEngine.Rigidbody
UnityEngine.GameObject::get_rigidbody()' in 'System.Void
Test.ClassReferencingObsoleteUnityAPIThroughEditorAssembly::Run()' replaced with 'T
UnityEngine.GameObject::GetComponent<UnityEngine.Rigidbody>()'.
The table below describes the values for the UNITY_APIUPDATER_LOG_THRESHOLD
environment variable:
Log threshold | Description |
---|---|
Error (default value) | The API updater only logs Error messages. Error messages are logged when the API updater fails to apply a specific update, which requires you to take corrective action (usually requesting the original assembly author to provide an updated version of the assembly). |
Warning | The API updater logs Warning and Error messages. Warning messages are logged when the API updater applies a change that the user might need to review. |
Info | The API updater logs Informational, Warning and Error messages. Info messages include updates applied by the AssemblyUpdater. |
Debug | The API updater logs all messages. This is useful for troubleshooting, for example if you have issues with the API updater that you want to report to Unity. |
The API updater couldn’t update all obsolete code. This can occur if the updater can’t save its changes, for example if the user has read-only permissions on the script.
Check the previous lines in the console to see any problems that occurred during the update process.
2018–07–31 Page amended
“accept-apiupdate” command line option added in Unity 2017.2
AssemblyUpdater logging improved in Unity 2018.3 NewIn20183
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.