BurstDiscardAttribute
Use this attribute to exclude a method or property from being compiled to native code by the Burst compiler.
Read time 4 minutesLast updated 10 days ago
Definition
- Type: Class
- Namespace: Unity.Burst
- Assembly: UnityEngine.ScriptingModule
- Inherits from: Attribute
[AttributeUsage(AttributeTargets.Method|AttributeTargets.Property)]public class BurstDiscardAttribute : Attribute
Remarks
By default, Burst compiles all methods in jobs decorated with the attribute. You can use the attribute on a method or property to exclude code from Burst compilation in situations where it can only run in .NET runtimes. For example, you can use to exclude methods that use managed objects to perform logging, or methods that check the validity of something only valid in a managed environment.
[BurstCompile][BurstDiscard][BurstDiscard]Examples
using Unity.Burst;using Unity.Collections;using Unity.Jobs;using UnityEngine;[BurstCompile]public struct MyJob : IJob{ // ... [BurstDiscard] public void NotExecutedInNative() { Debug.Log("This is a log from a managed job"); } public void Execute() { // The following method call will not be compiled NotExecutedInNative(); }}