Version: 2019.4
Assembly definitions
Assembly Definition Reference properties

Assembly Definition properties

Click on an Assembly Definition asset to set the properties for an assembly in the InspectorA Unity window that displays information about the currently selected GameObject, asset or project settings, allowing you to inspect and edit the values. More info
See in Glossary

Assembly Definition properties are divided into the following sections:

Name and General

Property Description
Name The name for the assembly (without a file extension). Assembly names must be unique across the Project. Consider using a reverse-DNS naming style to reduce the chance of name conflicts, especially if you want to use the assembly in more than one Project.

Note: Unity uses the name you assign to the Assembly Definition asset as the default value of the Name field, but you can change the name as desired. However, if you reference an Assembly Definition by its name rather than its GUID, changing the name will break the reference.
Allow ‘unsafe’ code Enable the Allow ‘unsafe’ Code option if you have used the C# unsafe keyword in a script within the assembly. When you enable this setting, Unity passes the /unsafe option to the C# compiler when it compiles the assembly.
Auto Referenced Specify whether the predefined assemblies should reference this Project assembly. When you disable the Auto Reference option, Unity does not automatically reference the assembly during compilation. This has no effect on whether Unity includes it in the build.
Override References Enable the Override References setting to manually specify which precompiled assemblies this assembly depends upon. When you enable Override References, the Inspector shows the Assembly References section, which you can use to specify the references.

A precompiled assembly is a library compiled outside your Unity Project. By default, assemblies you define in your Project reference all the precompiled assemblies you add to the Project, which matches how the predefined assemblies reference all precompiled assemblies. When you enable Override References, this assembly only references the precompiled assemblies you add under Assembly References. Note: To prevent Project assemblies from automatically referencing a precompiled assembly, you can disable its Auto Referenced option. See Plugin Inspector for more information.
No Engine References When you enable this property, Unity does not add references to UnityEditor or UnityEngine when it compiles the assembly.

See Creating an Assembly Definition asset

Define Constraints

Specifies the compiler #define directives that must be defined for Unity to compile or reference an assembly.

Unity only compiles and references a Project assembly if ALL of the Define Constraints are satisfied. Constraints work like the #if preprocessor directive in C#, but on the assembly level instead of the script level. You must define all the symbols in the Define Constraints setting for the constraints to be satisfied.

To specify that a symbol must be undefined, prefix it with a negating ! (bang) symbol. For example, if you specify the following symbols as the Define Constraints:


The constraints are satisfied when the symbol ENABLE_IL2CPP is not defined and the symbol UNITY_2018_3_OR_NEWER is defined. In other words, Unity only compiles and references this assembly on non-IL2CPP scripting runtimes for Unity 2018.3 or newer.

You can use the || (OR) operator to specify that at least one of the constraints must be present in order for the constraints to be satisfied. For example:


The constraints are satisfied when either UNITY_IOS or UNITY_EDITOR_OSX and UNITY_2019_3_OR_NEWER are defined and UNITY_ANDROID is not defined. Individual lines are analogous to performing a logical AND between the constraints in them. The above example is equivalent to:


You can use any of Unity’s built-in #define directives, symbols defined in a global compiler response (.rsp) file, and any symbols defined in the Project’s Scripting Define Symbols Player setting. See Platform dependent compilation for more information, including a list of the built-in symbols.

Note: The Scripting Define Symbols settings are platform-specific. If you use this setting to define whether Unity should use an assembly, make sure that you define the necessary symbols on all of the relevant platforms.

See Conditionally including an assembly.

Invalid or incompatible constraints

Unity marks each constraint with an indicator based on the currently defined settings. For example, the following set of two constraints indicates that one symbol is currently defined while the other is not. Since each individual constraint must be true for the overall constraint to be satisfied, the Define Constraints box is also marked as invalid or incompatible.

To satisfy the constraints in this example, you could change the Scripting BackendA framework that powers scripting in Unity. Unity supports three different scripting backends depending on target platform: Mono, .NET and IL2CPP. Universal Windows Platform, however, supports only two: .NET and IL2CPP. More info
See in Glossary
to IL2CPPA Unity-developed scripting back-end which you can use as an alternative to Mono when building projects for some platforms. More info
See in Glossary
(in the Player Settings). However, what often matters is how the constraints are evaluated when you build the project, not how the constraints appear in the Unity Editor. For example, you might have an assembly that you only want to include in builds that use the IL2CPP backend, but not on other builds that use the Mono backend.

Assembly Definition References

Property Description
Assembly Definition References Specify references to other assemblies that you have created using Assembly Definition assets. Unity uses these references to compile the assembly and also define the dependencies
See in Glossary
between assemblies.
Use GUIDs This setting controls how Unity serializes references to other Assembly Definition assets. When you enable this property, Unity saves the reference as the asset’s GUID, instead of the Assembly Definition name. It’s good practice to use the GUID instead of the name, because it means you can make changes to the name of an Assembly Definition asset without having to update other Assembly Definition files that reference it.

See Creating an Assembly Definition asset

Assembly References

The Assembly References section only appears when you enable the Override References property (in the General section). Use this area to specify any references to precompiled assemblies on which this assembly depends.

See Referencing a precompiled, plugin assembly


Set the platform compatibility of the assembly. Unity only compiles or references this assembly on the included (or not excluded) platforms.

See Creating a platform-specific assembly

Version Defines

Specify which symbols to define according to the versions of the packages and modules in a project.

Property Description
Resource. A package or module
Define. The symbol to define when an applicable version of the Resource is also present in this Unity Project.
Expression An expression defining a version or range of versions. See Version Define expressions.
Expression outcome The Expression evaluated as a logical statement, where “x” is the version checked. If the Expression outcome says, Invalid, then the Expression is malformed.

Defining symbols based on project packages

Assembly definitions
Assembly Definition Reference properties
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。