Search Unity

Deferred NativeArray IJobForEach_BC

Discussion in 'Entity Component System' started by RoughSpaghetti3211, Dec 18, 2019.

  1. RoughSpaghetti3211

    RoughSpaghetti3211

    Joined:
    Aug 11, 2015
    Posts:
    1,705
    Hello,

    Wondering if someone could help me out, how do I create a deferred NativeArray for IJobForEach_BC, the meshTrianglePositions array should only be create if a the GetMeshTrianglePositions executes.

    Code (CSharp):
    1.  
    2.  
    3. //
    4. // Get Mesh Positions
    5. var meshTrianglePositions = new NativeArray<Vector3>(triangleCount[0] * 3, Allocator.TempJob);
    6.  
    7. inputDeps = new GetMeshTrianglePositions
    8. {
    9.     MeshTrianglePositions = meshTrianglePositions,
    10.     TileBuffer = GetBufferFromEntity<TilesBufferComponent>(true)
    11. }.ScheduleSingle(_qTrianglesBuffer, inputDeps);
    12.  
    13.  
     
  2. eterlan

    eterlan

    Joined:
    Sep 29, 2018
    Posts:
    177
    I guess this GetMeshTrianglePositions require some component to run? You can simply call RequireForUpdate in OnCreate, or hide the creation logic inside a if-check,
    if (query.CalculateEntityCount > 0){// Create array, schedule job.}