Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Bug Why I can not see anything after create a entity with RenderMesh

Discussion in 'Graphics for ECS' started by TKOW, Aug 4, 2023.

  1. TKOW

    TKOW

    Joined:
    Mar 6, 2018
    Posts:
    4
    After running,I can see a entity in Entities Hierarchy which have Local Transform,Local To World and Render Mesh.The Scale of Local Transform is 3 and The Mesh and Material is not Null. I also create a GameObject with same Material and Mesh then I can see the model correctly.
    inspector.PNG scene.PNG 捕获.PNG
    Codes show below:
    Code (CSharp):
    1. using UnityEngine;
    2. using Unity.Entities;
    3. using Unity.Transforms;
    4. using Unity.Collections;
    5. using Unity.Rendering;
    6.  
    7. public class NewBehaviourScript : MonoBehaviour
    8. {
    9.      // Start is called before the first frame update
    10.         [SerializeField] private Mesh mesh;
    11.         [SerializeField] private Material material;
    12.         void Start()
    13.         {
    14.          
    15.             EntityManager entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;
    16.             EntityArchetype entityArchetype = entityManager.CreateArchetype( typeof(LocalTransform),typeof(RenderMesh),typeof(LocalToWorld));
    17.          
    18.             //Entity entity= entityManager.CreateEntity(entityArchetype);
    19.             NativeArray<Entity> entityArray = new NativeArray<Entity>(1, Allocator.Temp);
    20.             entityManager.CreateEntity(entityArchetype, entityArray);
    21.             //entityManager.SetComponentData(entity,new levelComponent{level =114514});
    22.             for (int i = 0; i < entityArray.Length; i++)
    23.             {
    24.                 Entity entity = entityArray[i];
    25.                 entityManager.SetComponentData(entity,new LocalTransform(){Scale = 3});
    26.                 entityManager.SetSharedComponentManaged(entity,new RenderMesh() {mesh = mesh,material = material});
    27.             }
    28.  
    29.             entityArray.Dispose();
    30.         }
    31. }
    32.  
     
  2. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    4,012
    TKOW and Anthiese like this.
  3. TKOW

    TKOW

    Joined:
    Mar 6, 2018
    Posts:
    4