Custom scripting symbols
Create your own custom scripting symbols via the Editor UI, from scripts, or with an asset file.
Read time 4 minutesLast updated 12 days ago
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:
- An asset file, for symbols that apply for all Editor and Player code in the project, regardless of the active build profile.
- Player Settings, for symbols that apply for all Editor and Player code when the given platform or one of its build profiles are active.
- A build profile, for symbols that apply for all Editor and Player code when the given build profile is active.
- From code, for symbols that apply for the active platform or for individual Player builds, depending on the API used.
Custom symbols for the whole project
You can define custom scripting symbols that apply for the whole project with a response file asset as follows:
- Name the file and place it in the root of your project's Assets folder.
csc.rsp - Define scripting symbols on lines that start with , followed by one or more semicolon-separated scripting symbols.
-define:
Unity reads this file at startup and applies it before compiling any code. For example, if you include the single line in your file, the symbols and are included as globally defined scripting symbols for all C# scripts in the project.
-define:UNITY_DEBUG;UNITY_TESTcsc.rspUNITY_DEBUGUNITY_TESTCustom symbols for a platform
You can define custom scripting symbols specific to a platform as follows:
- Open Player settings.
- Navigate to the Scripting Define Symbols list in the Other Settings > Script Compilation section.
- Add new scripting symbols to the list by selecting the + button and typing the name of the symbol in the text field. Remove existing list items with the - button.
- When you've finished editing the list, select Apply to apply your changes. Unity recompiles the scripts in your project using the new symbols.
Custom symbols for a build profile
You can define custom scripting symbols for a build profile as follows:
- Select the build profile you want to define symbols for in the Build Profiles window.
- Select Add Settings > Scripting Defines. A scripting defines list appears in the Scripting Defines foldout.
- Add new scripting symbols to the list by selecting the + button and typing the name of the symbol in the text field. Remove existing list items with the - button. Modifications to the list save and apply automatically.
Custom symbols defined from code
You can use the following APIs to define scripting symbols:
PlayerSettings.SetScriptingDefineSymbolsBuildPlayerOptions.extraScriptingDefinesBuild.Player.ScriptCompilationSettings-extraScriptingDefines
BuildPlayerOptions.extraScriptingDefinesBuild.Player.ScriptCompilationSettings-extraScriptDefinesPlayerSettings.SetScriptingDefineSymbolsCustom symbols in batch mode
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.
Scripting symbol inheritance
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 ) + 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.
csc.rspFor example, assume your project has the following custom scripting symbols defined in the following locations:
Location | Symbols defined |
|---|---|
| |
| Windows Player Settings | |
| WindowsBuildProfile1 | |
| WindowsBuildProfile2 | |
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 | |
| Windows | |
| WindowsBuildProfile1 | |
| WindowsBuildProfile2 | |
You can test this behavior with directives in your code. For more information, refer to Test conditional compilation.
#if