Search Unity

Is This Right? How to render using Hybrid Renderer

Discussion in 'Graphics for ECS' started by MaxXR, May 23, 2019.

  1. MaxXR

    MaxXR

    Joined:
    Jun 18, 2017
    Posts:
    67
    Hi
    Am trying visualise a NativeArray of entities using ECS. The code below runs and entities get created but nothing renders on the screen. I followed this tutorial so can't figure out why it's not working. Tested on OSX and windows machine. Same result. How does one render stuff using ECS?

    Are there any up to date resources where it's clearly laid out i can follow (many are not up to date)?
    If yes, please comment and share. Other ideas also appreciated. Impressed at the performance thus far with ECS!
    Thanks :)

    Am using:
    • 2019.1.2f1
    • (package) Hybrid Renderer preview 12 - 0.01
    • (package) Entities preview 30 - 0.0.12
    When play, nothing shows.


    Code (CSharp):
    1. using UnityEngine;
    2. using Unity.Entities;
    3. using Unity.Transforms;
    4. using Unity.Rendering;
    5. using UnityEditor;
    6. using Unity.Collections;
    7.  
    8. public class EntityHandler : MonoBehaviour
    9. {
    10.     private static EntityManager entityManager;
    11.     [SerializeField] public Mesh mesh;
    12.     [SerializeField] public Material material;
    13.  
    14.     [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.AfterSceneLoad)]
    15.     public void Start()
    16.     {
    17.         EntityManager entityManager = World.Active.EntityManager;
    18.         int size = 5;
    19.  
    20.         //create Archetype
    21.         EntityArchetype entityArchetype = entityManager.CreateArchetype(
    22.             typeof(Translation),
    23.             typeof(LocalToWorld),
    24.             typeof(RenderMesh),
    25.             typeof(Scale));
    26.  
    27.         //create array to hold entities
    28.         NativeArray < Entity > entityArray = new NativeArray<Entity>(size, Allocator.Temp);
    29.  
    30.         //fill array with entities
    31.         entityManager.CreateEntity(entityArchetype, entityArray);
    32.         for (int i = 0; i < entityArray.Length; i++)
    33.         {
    34.             Entity e = entityArray[i];
    35.             entityManager.SetSharedComponentData(e, new RenderMesh
    36.             {
    37.                 mesh = mesh,
    38.                 material = material,
    39.             });
    40.         }
    41.     }
    42. }
     
  2. elcionap

    elcionap

    Joined:
    Jan 11, 2016
    Posts:
    138
    Your are adding a scale component without setting any value.
    Code (CSharp):
    1. entityManager.SetComponentData(e, new Scale { Value = 1 } );
    []'s
     
  3. recursive

    recursive

    Joined:
    Jul 12, 2012
    Posts:
    669
    To add to what @elcionap stated: If you add a component without setting a value, or create directly from an archetype, the values will initialize to default(T) which in most cases the underlying fields will be set to 0.

    If you create from a prefab those values will be copied instead.
     
  4. MaxXR

    MaxXR

    Joined:
    Jun 18, 2017
    Posts:
    67
    Legend!

    Awesome thanks