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.