Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Set SharedComponentData for Rendermesh in Job

Discussion in 'Graphics for ECS' started by Captain_Pineapple, Jul 31, 2019.

  1. Captain_Pineapple

    Captain_Pineapple

    Joined:
    Nov 9, 2016
    Posts:
    6
    Hello there,

    i'm kinda new to ecs so perhaps i just missed something obvious but my setup is as follows:

    I have a job in which i process cubes. Under certain conditions i will use the EntitiyCommandBuffer to schedule the creation of new cubes which should also have the same rendermesh as the cubes before. (or even any rendermesh with a valid mesh and material)

    Code (CSharp):
    1. _entityCommandBuffer.AddSharedComponent(i, e, new RenderMesh());
    Problem is: Those cannot be given to a job since a rendermesh contains a mesh/material which is a non-value type. Thus only entities that are manually created outside of jobs have visuals atm.



    I also though about checking all chunks after completing my jobs for chunks that are yet missing a rendermesh and setting the data there but this only gives me a nullref somewhere in archetypechunkarray.

    Code (CSharp):
    1. for(int i=0;i< allChunks.Length;i++)
    2.             {
    3.                 if(!allChunks[i].HasChunkComponent(new ArchetypeChunkComponentType<WorldRenderBounds>()))
    4.                 {
    5.                     //EntityManager.set<RenderMesh>(allChunks[i],m_renderMesh);
    6.                     allChunks[i].SetChunkComponentData(new ArchetypeChunkComponentType<RenderMesh>(), m_renderMesh);
    7.                 }
    8.             }
    I feel like i cannot be the only person who tries to create new entities with visuals from a job without having to iterate all entities all over after the job is done since this would kind of destroy the whole sense of having a job in the first place.

    Thanks in advance for any insight on this...