Search Unity

  1. Calling all beginners! Join the FPS Beginners Mods Challenge until December 13.
    Dismiss Notice
  2. It's Cyber Week at the Asset Store!
    Dismiss Notice

Invisible entity (MeshInstanceRenderer or SetSharedComponentData issue)

Discussion in 'Data Oriented Technology Stack' started by Anthelmed, Aug 4, 2018.

  1. Anthelmed

    Anthelmed

    Joined:
    Mar 2, 2017
    Posts:
    8
    Hello, I'm not sure why, but my entity doesn't appear at all in my scene (game and scene window), and I don't have any errors.
    I think either the MeshInstanceRenderer not work or the SetSharedComponentData not update correctly.

    I'm using Unity 2018.2.1f1.

    Code (Json):
    1. {
    2.     "dependencies": {
    3.         ...
    4.         "com.unity.burst": "0.2.4-preview.23",
    5.         "com.unity.entities": "0.0.12-preview.8"
    6.      }
    7. }
    8.  
    Code (CSharp):
    1. using Unity.Entities;
    2. using Unity.Mathematics;
    3. using Unity.Rendering;
    4. using Unity.Transforms;
    5. using UnityEngine;
    6.  
    7. public class Bootstrap : MonoBehaviour
    8. {
    9.     public Mesh PlayerMesh;
    10.     public Material PlayerMaterial;
    11.  
    12.     private void Start()
    13.     {
    14.         var entityManager = World.Active.GetOrCreateManager<EntityManager>();
    15.  
    16.         var playerArchetype = entityManager.CreateArchetype(
    17.             typeof(TransformMatrix),
    18.             typeof(Position),
    19.             typeof(MeshInstanceRenderer)
    20.         );
    21.  
    22.         var player = entityManager.CreateEntity(playerArchetype);
    23.  
    24.         entityManager.SetComponentData(player, new Position { Value = new float3(0f, 0f, 1f) });
    25.  
    26.         entityManager.SetSharedComponentData(player, new MeshInstanceRenderer
    27.         {
    28.             mesh = PlayerMesh,
    29.             material = PlayerMaterial
    30.         });
    31.     }
    32. }
     
  2. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    1,907
    Is your player a skinned mesh? Because I don't believe that's supported yet.
     
  3. Anthelmed

    Anthelmed

    Joined:
    Mar 2, 2017
    Posts:
    8
    Nope, i'm using a primitive cube and a material with the default built-in shader.


     
  4. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    1,907
    Not sure what to suggest then. I copied your code and it worked fine for me.

    upload_2018-8-4_12-32-26.png
     
  5. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    6,411
    Maybe try recreate project, and paste code again?
    Or recreate mesh and texture?
    Refresh.
     
  6. Anthelmed

    Anthelmed

    Joined:
    Mar 2, 2017
    Posts:
    8
    Thanks for your help, I think my only option is to make a fresh project like Antypodish suggest.
     
  7. xSidia

    xSidia

    Joined:
    Mar 15, 2019
    Posts:
    2
    Just if future users end up here:

    You need to include the hybrid renderer package
     
    RobSCoatsink, starikcetin and Zanval like this.
  8. Rs

    Rs

    Joined:
    Aug 14, 2012
    Posts:
    39
    I stumbled into this trouble too. I do have the Hybrid Renderer package installed (Unity 2019.2.3.f1)
    I have attached the manifest.json file in case someone wants to check .
    I have this situation in the Entity Debugger which might give a clue.
    2019-08-28 15_57_52-.png

    I tested in Unity 2019.1.1 and 2019.2.3.f1 and the problem is the same. The Entities are created but I can see nothing.
    Am I doing something wrong?
    Or is the DOTS stack conflicting with Post Processing?
    Or, maybe more likely, I noticed that in every Entity, WorldRenderBounds extents is (0,0,0), could that be the cause?
    Any help would be super!
     

    Attached Files:

    Last edited: Aug 28, 2019
  9. Rs

    Rs

    Joined:
    Aug 14, 2012
    Posts:
    39
    Answering myself. I noticed that LocalToWorld was all 0 in every entity which led me to realize I forgot to add a Translation component when creating the archetype.
    Translation is pretty much needed for anything that has to be rendered, am I right?
    See ADDED LINE (line 22)

    Code (CSharp):
    1.  
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5. using Unity.Entities;
    6. using Unity.Collections;
    7. using Unity.Rendering;
    8. using Unity.Transforms;
    9. using UnityEngine.Assertions;
    10.  
    11. public class WAMParticleSystemWIthECS : MonoBehaviour
    12. {
    13.     [SerializeField] Mesh mesh;
    14.     [SerializeField] Material material;
    15.  
    16.    void Awake() {
    17.         // Grab the entity manager instance
    18.         EntityManager entityManager = World.Active.EntityManager;
    19.         // Create an entity archetype
    20.         EntityArchetype entityArchetype = entityManager.CreateArchetype(
    21.             typeof(BoidComponent),
    22.             typeof(Translation), // ADDED LINE
    23.             typeof(RenderMesh),
    24.             typeof(LocalToWorld)
    25.             //typeof(WorldRenderBounds)
    26.             );
    27.  
    28.         // Allocate NativeArray to collect the entities
    29.         NativeArray<Entity> entities = new NativeArray<Entity>(4, Allocator.Temp);
    30.  
    31.         // Create an entity from the archetype
    32.         entityManager.CreateEntity(entityArchetype, entities);
    33.  
    34.         for (int i = 0; i < entities.Length; i++) {
    35.             Entity entity = entities[I];
    36.             // Use the entity manager to set the component's data
    37.             entityManager.SetComponentData<BoidComponent>(entity, new BoidComponent {
    38.                 position = new Unity.Mathematics.float3(0.1f, 0.1f, 0.1f),
    39.                 velocity = new Unity.Mathematics.float3(0.01f, 0.01f, 0.01f),
    40.                 rotation = Unity.Mathematics.quaternion.Euler(new Unity.Mathematics.float3(0f,10f,1f))
    41.             });
    42.  
    43.             Assert.IsNotNull(mesh);
    44.             entityManager.SetSharedComponentData(entity, new RenderMesh {
    45.                 mesh = mesh,
    46.                 material = material
    47.             });
    48.  
    49.             //WorldRenderBounds wrb = entityManager.GetComponentData<WorldRenderBounds>(entity);
    50.             //wrb.Value.Extents = new Unity.Mathematics.float3(100f, 100f, 100f);
    51.             //entityManager.SetComponentData(entity, wrb);
    52.         }
    53.  
    54.         // free
    55.         entities.Dispose();
    56.     }
    57. }
    58.