Version: 2022.1
LanguageEnglish
  • C#

BurstDiscardAttribute

class in Unity.Burst

/

Implemented in:UnityEngine.CoreModule

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Description

The BurstDiscard attribute lets you remove a method or property from being compiled to native code by the burst compiler.

By default, a job compiled with burst will compile all methods. In some cases, you could have managed methods that cannot be compiled to native (e.g checking for validity only valid in a managed environment or logging using managed objects...etc) and should not be executed at runtime. In that case you can use this attribute to mark a method or property as not compilable by the burst compiler.

using Unity.Burst;
using Unity.Collections;
using Unity.Jobs;
using UnityEngine;

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(); } }