AlwaysLinkAssemblyAttribute

class in UnityEngine.Scripting

Switch to Manual

Description

Ensure an assembly is always processed during managed code stripping.

Use the [assembly: UnityEngine.Scripting.AlwaysLinkAssembly] attribute to force UnityLinker to process the assembly regardless of whether or not the assembly is referenced by another assembly that is included in the build.

Use this attribute on package or precompiled assemblies that contain one or more methods with the [RuntimeInitializeOnLoadMethod] attribute, but which may not contain types used directly or indirectly in any scenes built for the project.

Note that this attribute only instructs UnityLinker to process the assembly. If no code elements match the root marking rules for the assembly, UnityLinker still removes the assembly from the build.

The [AlwaysLinkAssembly] attribute can only be defined on the assembly. Declare the attribute in any C# file compiled into the assembly, outside the namespace declaration.

See Also: Managed Code Stripping

using UnityEngine;
using UnityEngine.Scripting;

[assembly: AlwaysLinkAssembly]

namespace Example { public class Foo { [RuntimeInitializeOnLoadMethod] public void Initialize() {} } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961