Firstborn/Library/PackageCache/com.unity.burst@1.8.4/Documentation~/compilation-burstdiscard.md
Schaken-Mods 9092858a58 updated to the latest editor
I updated everything to the latest Unity Editor. Also realized I had the wrong shaders on my hairs, those are fixed and the hairs look MUCH better!
2023-05-07 17:43:11 -05:00

1008 B

BurstDiscard attribute

If you're running C# code not inside Burst-compiled code, you might want to use managed objects, but not compile these portions of code within Burst. To do this, use the [BurstDiscard] attribute on a method:

[BurstCompile]
public struct MyJob : IJob
{
    public void Execute()
    {
        // Only executed when running from a full .NET runtime
        // this method call will be discard when compiling this job with
        // [BurstCompile] attribute
        MethodToDiscard();
    }

    [BurstDiscard]
    private static void MethodToDiscard(int arg)
    {
        Debug.Log($"This is a test: {arg}");
    }
}

Note

A method with [BurstDiscard] can't have a return value.

You can use a ref or out parameter, which indicates whether the code is running on Burst or managed:

[BurstDiscard]
private static void SetIfManaged(ref bool b) => b = false;

private static bool IsBurst()
{
    var b = true;
    SetIfManaged(ref b);
    return b;
}