In addition to Unity’s built-in scripting symbols, you can define your own custom scripting symbols. Where you define custom scripting symbols determines the scope in which they apply. You can define custom symbols in the following places:
You can define custom scripting symbols that apply for the whole project with a response file asset as follows:
csc.rsp
and place it in the root of your project’s Assets folder.-define:
, followed by one or more semicolon-separated scripting symbols.Unity reads this file at startup and applies it before compiling any code. For example, if you include the single line -define:UNITY_DEBUG;UNITY_TEST
in your csc.rsp
file, the symbols UNITY_DEBUG
and UNITY_TEST
are included as globally defined scripting symbols for all C# 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 in the project.
Note: Changes to .rsp
files don’t take effect until Unity recompiles scripts. You can trigger recompilation by updating or reimporting a single script file.
You can define custom scripting symbols specific to a platform as follows:
Note: The Copy Defines button copies the current set of custom scripting symbols from the list into your clipboard as a string of semicolon-separated values.
You can define custom scripting symbols for a build profile as follows:
Note: You can launch the Editor with the -activeBuildProfile
command line argument to make the specified build profile and its custom scripting symbols applicable from startup.
You can use the following APIs to define scripting symbols:
PlayerSettings.SetScriptingDefineSymbols
BuildPlayerOptions.extraScriptingDefines
Build.Player.ScriptCompilationSettings-extraScriptingDefines
BuildPlayerOptions.extraScriptingDefines
and Build.Player.ScriptCompilationSettings-extraScriptDefines
only apply to Player builds, so when defining scripting symbols that apply to your Editor scripts, use PlayerSettings.SetScriptingDefineSymbols
. This is the code equivalent of configuring platform-specific scripting symbols in the Player settings.
Important: Symbols created from code with SetScriptingDefineSymbols
don’t take effect until the Editor regains control and recompiles your scripts. For example, if you create scripting symbols with SetScriptingDefineSymbols
in an Editor script and then call BuildPipeline.BuildPlayer
on the next line, the new symbols created in the previous line won’t be in effect yet. In this case any Editor code that runs as part of the BuildPlayer
execution runs without the new symbols and the Player might not build as intended.
When the Editor runs in batch mode, there’s no mechanism to trigger recompilation of scripts. If you need specific symbols to be defined in an Editor running in batch mode, they must be in place from startup using a csc.rsp asset file.
If you define custom scripting symbols in several places, Unity adds together all the symbols that apply for the current build configuration. Symbols are inherited from each scope rather than overwritten, as follows: Project-wide symbols (from csc.rsp
) + Platform-specific symbols (from Player settings) + Build profile symbols (from Build Data). Platform and build profile symbols are only included if they match the active build profile.
For example, assume your project has the following custom scripting symbols defined in the following locations:
Location | Symbols defined |
---|---|
csc.rsp |
SYMBOL_A |
Windows Player Settings | SYMBOL_B |
WindowsBuildProfile1 | SYMBOL_C |
WindowsBuildProfile2 | SYMBOL_D |
Given this example configuration, the following table shows which symbols are active for your Editor and Player code when different build profiles are active:
Active build profile | Active symbols |
---|---|
Android | SYMBOL_A |
Windows |
SYMBOL_A , SYMBOL_B
|
WindowsBuildProfile1 |
SYMBOL_A , SYMBOL_B , SYMBOL_C
|
WindowsBuildProfile2 |
SYMBOL_A , SYMBOL_B , SYMBOL_D
|
You can test this behavior with #if
directives in your code. For more information, refer to Test conditional compilation.
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.
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.