Search Unity

Issue with RenderMesh component -> MEsh not displayed

Discussion in 'Graphics for ECS' started by Erenquin, Feb 26, 2020.

  1. Erenquin

    Erenquin

    Joined:
    Apr 9, 2018
    Posts:
    164
    Hello,
    trying to follow 1st CodeMonkey Tutorial on ECS:


    At 14:40, in my implementation the RenderMesh does not appear.
    Not sure what I'm doing wrong.

    Code:
    Code (CSharp):
    1.     [SerializeField] Mesh mesh;
    2.     [SerializeField] Material material;
    3.  
    4.     // Start is called before the first frame update
    5.     void Start()
    6.     {
    7.         EntityManager entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;
    8.  
    9.         EntityArchetype entityArchetype = entityManager.CreateArchetype(
    10.             typeof(LevelComponent),
    11.             typeof(Translation),
    12.             typeof(RenderMesh),
    13.             typeof(LocalToWorld)
    14.         );
    15.  
    16.         NativeArray<Entity> entityArray = new NativeArray<Entity>(1, Allocator.Temp);
    17.         entityManager.CreateEntity(entityArchetype, entityArray);
    18.  
    19.         for (int i = 0; i < entityArray.Length; i++)
    20.         {
    21.             Entity entity = entityArray[i];
    22.             entityManager.SetComponentData(entity, new LevelComponent { level = Random.Range(10, 20) });
    23.  
    24.             entityManager.SetSharedComponentData(entity, new RenderMesh
    25.             {
    26.                 mesh = mesh,
    27.                 material = material
    28.             });
    29.  
    30.         }
    31.  
    32.         entityArray.Dispose();
    33.     }
    Setup in Unity (I first tried with the quad and a sprite texure as in the Tutorial, then a cube and a more simple material):
    upload_2020-2-26_11-18-4.png

    Does the entity Archetype require additional components for the render mesh to work ? If yes, which ones ?
    Any other hint on why it does not work ?

    Thanks for the help.
     
  2. siggigg

    siggigg

    Joined:
    Apr 11, 2018
    Posts:
    247
    Install the Hybrid renderer package.
     
    TipRC likes this.
  3. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,685
    Add RenderBounds and set bounds by mesh.bounds.ToAABB(). From 0.6.0 behaviour changed, now you should declare RenderBounds manually for entities created frrom scratch in code.
     
    vijaypandu6, bb8_1, Aratow and 4 others like this.
  4. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,685
    He already has it I guess (because RenderMesh not throw him error :) )
     
    siggigg likes this.
  5. Erenquin

    Erenquin

    Joined:
    Apr 9, 2018
    Posts:
    164
    Thanks a lot that did it.
    I only had to add RenderBounds in the Archetype.
    No need to set the AABB value.
     
    rc82 likes this.
  6. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,685
    Thus it will be incorrect zero sized bounds and on view edges it wouldn't render, because it will calc frustrum culling by pivot point only.
     
  7. Erenquin

    Erenquin

    Joined:
    Apr 9, 2018
    Posts:
    164
    Ok, I see, thanks :)
     
  8. rc82

    rc82

    Joined:
    Jan 28, 2020
    Posts:
    44
    ... after about 5 hours of trying all sorts of things, this one comment fixed it all. THANK YOU.
     
  9. Nothke

    Nothke

    Joined:
    Dec 2, 2012
    Posts:
    112
    Uhhh, why was this never mentioned? The Hybrid Renderer changelog is full of "Updated dependencies of this package." But nothing about actual changes. The front page still says

    "An entity is rendered if it has both a LocalToWorld component, from the Unity.Transforms namespace, and a RenderMesh component, from the Unity.Rendering namespace. The Hybrid Renderer systems adds other components needed for rendering, such as RenderBounds and PerInstanceCullingTag, automatically"

    Please, please, Unity, update the docs after each change, how hard can it be?
     
    ReadPan_ likes this.
  10. appnext

    appnext

    Joined:
    Oct 1, 2017
    Posts:
    1
    I have tried following the same tutorial but have hit the same problem.
    Entities are being created but no Meshes are displayed on camera.

    The only changes i have made are to the EntityManager definition

    EntityManager entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;

    and adding typeof(RenderBounds) to the Archetype

    Adding this has no effect for me:
    entityManager.SetComponentData(entity,
    new RenderBounds
    {
    Value = mesh.bounds.ToAABB()
    }
    );

    The packages and versions I am isung are as follows:
    - Unity 2019.3.0f3
    - Burst 1.2.3
    - Entities 0.6.0
     
  11. Erenquin

    Erenquin

    Joined:
    Apr 9, 2018
    Posts:
    164
    Yes I think I had to create the entity manager as you.

    As for your issue, I have no idea. For me it worked.
    Did you check your mesh can be displayed without using ECS (like standard object: drag & drop in the hierarchy/scene).
     
  12. SebastianAaltonen

    SebastianAaltonen

    Unity Technologies

    Joined:
    Feb 21, 2020
    Posts:
    112
    I rewrote the hybrid renderer documentation last week. The new document corrects all the wrong info (such as this one), and adds new information about Hybrid V1 and Hybrid V2, supported feature set and how to correctly setup materials/shaders for hybrid renderer. Hybrid V1 is especially picky about the way you need to setup your assets to make it render correctly. Otherwise you will see issues like rendering to (0,0,0) or flickering.

    Hopefully the new document helps with issues like this. We now have a dedicated team improving hybrid renderer. We will ensure that the documentation stays up to date in the future.
     
  13. richterk

    richterk

    Joined:
    Nov 14, 2016
    Posts:
    2

    I actually have a weird variation of this bug. So, I'm rendering an isomorphic grid. In my grid node, I generate a rotated quad mesh and assign the mesh and material. Oddly, if I specify a non-uniform scale set to the position vector:
    Code (CSharp):
    1.  
    2. ecbp.SetComponent<NonUniformScale>(entity.Index, entity, new NonUniformScale
    3.             {
    4.                 Value = new float3{
    5.                     x =
    6. (gridNodes[index].x - gridNodes[index].y) * gridNodes[index].tileWidth/2,
    7.                     y =
    8. (gridNodes[index].y + gridNodes[index].x) * gridNodes[index].tileHeight/2,
    9.                     z = 0
    10.                 }
    11.             });
    12.  
    then the meshes render (wrongly, obviously). However, if I set it to a non-uniform scale at a reasonable value, or if I use Scale at all, it doesn't render at all. Nearly impossible to debug, and all of the values are reasonable in the entity debugger for all of the entities.
     
    Last edited: Nov 21, 2021
  14. JussiKnuuttila

    JussiKnuuttila

    Unity Technologies

    Joined:
    Jun 7, 2019
    Posts:
    351
    In a case like this I would suggest starting with a RenderDoc capture to see whether the expected meshes are rendering at all (but possibly producing no output pixels due to something going wrong, such as incorrect transform), or whether the draw calls have been dropped for some reason (which could indicate a problem with culling).
     
  15. tylearymf_unity

    tylearymf_unity

    Joined:
    May 25, 2022
    Posts:
    12
    I tried to set LayerMask to -1 and it was displayed successfully.

    Code (CSharp):
    1. var layerMask = -1;
    2.         renderMesh.layerMask = (uint)layerMask;
    3.         RenderMeshUtility.AddComponents(entityProto, EntityManager, new RenderMeshDescription() { RenderMesh = renderMesh });