Search Unity

RenderBounds automatically created, but extents not set

Discussion in 'Graphics for ECS' started by AnmAtAnm, Mar 13, 2020.

  1. AnmAtAnm

    AnmAtAnm

    Joined:
    Nov 2, 2019
    Posts:
    3
    I'm surprised the hybrid render system will create a RenderBounds and WorldRenderBounds if there is a RenderMesh, but not set the extents of the components.

    Someone else mentioned the issue here. They mentioned the issue seemed to be version related, but I haven't seen a version combination that set it. I created my own minimal script (below) to toy with the issue.

    Am I missing a step that I should be taking, short of manually creating and updating the RenderBounds component? Or is it supposed to doing this, and there is currently a bug?

    Code (CSharp):
    1. public class CreateCube : MonoBehaviour
    2. {
    3.     public Mesh CubeMesh;
    4.     public Material Material;
    5.  
    6.     EntityArchetype cubeArchetype;
    7.     ComponentType[] cubeComponentTypes = new ComponentType[]
    8.         {
    9.                 ComponentType.ReadWrite<RenderBounds>(),
    10.                 ComponentType.ReadWrite<WorldRenderBounds>(),
    11.                 ComponentType.ReadWrite<LocalToWorld>(),
    12.                 ComponentType.ReadWrite<Rotation>(),
    13.                 ComponentType.ReadWrite<Translation>(),
    14.                 ComponentType.ReadWrite<RenderMesh>(),
    15.         };
    16.  
    17.     void Start()
    18.     {
    19.         // Initialization
    20.         var world = World.DefaultGameObjectInjectionWorld;
    21.         var manager = world.EntityManager;
    22.  
    23.         cubeArchetype = manager.CreateArchetype(cubeComponentTypes);
    24.  
    25.         var cube = manager.CreateEntity(cubeArchetype);
    26.         manager.SetComponentData<Translation>(cube,
    27.             new Translation() { Value = new float3() });
    28.         manager.SetComponentData<Rotation>(cube,
    29.             new Rotation() { Value = quaternion.identity });
    30.         manager.SetSharedComponentData<RenderMesh>(cube,
    31.             new RenderMesh() {
    32.                 material = Material,
    33.                 mesh = CubeMesh
    34.             });
    35.     }
    36. }
     
  2. siggigg

    siggigg

    Joined:
    Apr 11, 2018
    Posts:
    247
    If you use the conversion workflow the bounds are created for you, but if you create an entity manually you need to add and calculate the bounds yourself.

    There were quite a few thread on this recently.
     
  3. AnmAtAnm

    AnmAtAnm

    Joined:
    Nov 2, 2019
    Posts:
    3
    Cool. thanks. I just had to check I didn't miss something.
    It still feels weird that automatic component creation doesn't take the extra step, but I have no complaints doing it myself.
     
  4. siggigg

    siggigg

    Joined:
    Apr 11, 2018
    Posts:
    247
    Am I missing something, what automatic component creation are you referring to? You are adding the RenderBounds in your archetype?

    Code (CSharp):
    1. ComponentType.ReadWrite<RenderBounds>(),
    2. ComponentType.ReadWrite<WorldRenderBounds>(),