Unable to draw from IJobEntity

Aline 1.6.4
Unity 2022.2.0f1
Entities 1.0.0pre15

The example using IJob works fine, but when using ALINE inside IJobEntity, nothing draw, no error either.

Test Code:

using Drawing;
using Unity.Burst;
using Unity.Entities;
using Unity.Mathematics;
using UnityEngine;


public class DrawTest : MonoBehaviour
{
    void Start()
    {
        var manager = World.DefaultGameObjectInjectionWorld.EntityManager;
        var entity = manager.CreateEntity();
        manager.AddComponentData(entity, new DrawCom());

        print("draw test");
    }
}

public struct DrawCom : IComponentData
{
    public int Value;
}

public partial struct DebugDrawSystem : ISystem
{
    public CommandBuilder builder;

    [BurstCompile]
    public void OnCreate(ref SystemState state)
    {
    }

    [BurstCompile]
    public void OnDestroy(ref SystemState state)
    {
    }

    [BurstCompile]
    public void OnUpdate(ref SystemState state)
    {
        var builder = DrawingManager.GetBuilder(true);

        var job = new DebugDrawJob { builder = builder, offset = new float2(Time.time * 0.2f, Time.time * 0.2f), };
        job.Run();
    }
}

public partial struct DebugDrawJob : IJobEntity
{
    public CommandBuilder builder;
    public float2 offset;

    Color Colormap(float x)
    {
        // Simple color map that goes from black through red to yellow
        float r = math.clamp(8.0f / 3.0f * x, 0.0f, 1.0f);
        float g = math.clamp(8.0f / 3.0f * x - 1.0f, 0.0f, 1.0f);
        float b = math.clamp(4.0f * x - 3.0f, 0.0f, 1.0f);

        return new Color(r, g, b, 1.0f);
    }

    void Execute(ref DrawCom com)
    {
        for (int index = 0; index < 100 * 100; index++)
        {
            Draw(index);
        }
    }

    public void Draw(int index)
    {
        int x = index / 100;
        int z = index % 100;

        var noise = Mathf.PerlinNoise(x * 0.05f + offset.x, z * 0.05f + offset.y);
        Bounds bounds = new Bounds(new float3(x, 0, z), new float3(1, 14 * noise, 1));

        builder.SolidBox(bounds, Colormap(noise));
    }
}

Hi

You need to dispose the CommandBuilder to make it submit everything.

...
job.Run();

builder.Dispose();

or if you run it using the job system:

builder.DisposeAfter(jobHandle);

See Drawing from a Job/ECS - ALINE

Thank you, it works, it’s easy to forget.

1 Like