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(); } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961