Support Forum

Label2D inside Burst Job

Hi there, I am trying to use Label2D inside of a Burst Job, but it is not working.

I see on the documentation for Label2D, it says " This method cannot be used inside of Burst jobs. See Drawing from a Job/ECS instead."
However the page on Burst usage does not mention anything about Label2D as far as I can see.

This is the code I am using to try it, rendering things like lines and boxes works as expected:

var drawingBuilder = DrawingManager.GetBuilder(true);

Entities.WithName("DebugDrawing")
    .ForEach((in GridItem gridItem) =>
    {
        drawingBuilder.Label2D(gridItem.Position, "Test", 10f, LabelAlignment.Center, Color.white);
    })
    .WithBurst().Schedule();

drawingBuilder.DisposeAfter(Dependency);

Is it simply not possible to draw text from within Burst Jobs?

Hi

I don’t think strings can be used at all from within burst jobs. So I think this might be tricky.
There are some burst-specific strings like FixedString128, but there’s currently no support for them in ALINE. I don’t think it would be too hard to add though.

Appreciate the quick reply! I believe you are correct with strings support in Burst Jobs, user defined functions/methods don’t allow strings to be passed, they must use the FixedString* structs as per this.

I think adding support for the FixedString structs could work, but I’ll leave that up to you to decide. Updated code to use that could be something like:

struct GridItem
{
    public float3 Position;
    public float Distance;
}

var drawingBuilder = DrawingManager.GetBuilder(true);

Entities.WithName("DebugDrawing")
    .ForEach((in GridItem gridItem) =>
    {
        FixedString128 distance = $"Dist: {gridItem.Distance}";
        drawingBuilder.Label2D(gridItem.Position, distance, 10f, LabelAlignment.Center, Color.white);
    })
    .WithBurst().Schedule();

drawingBuilder.DisposeAfter(Dependency);
1 Like

Hi

This will be supported in the next version of the package!

if (x % 10 == 0 && z % 10 == 0) {
	Unity.Collections.FixedString128 label = $"({x} {z})";
	builder.Label2D(bounds.center, ref label, 12, LabelAlignment.BottomLeft);
}

1 Like

Thanks for the super fast turnaround @aron_granberg, I really appreciate it. I will be recommending this package to everyone I know :grinning:

I’m glad you appreciate it @drjaydenm .
If you want to support the package even more, a rating and/or review in the Asset Store is always much appreciated :slight_smile:

1 Like

Hey @aron_granberg, I just wanted to check when you are planning on releasing this new version of the package? Thanks

Hi

Probably not too long. But likely not within the next 2 weeks, though.