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

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.


Codes show below:

using UnityEngine;
using Unity.Entities;
using Unity.Transforms;
using Unity.Collections;
using Unity.Rendering;

public class NewBehaviourScript : MonoBehaviour
{
     // Start is called before the first frame update
        [SerializeField] private Mesh mesh;
        [SerializeField] private Material material;
        void Start()
        {
         
            EntityManager entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;
            EntityArchetype entityArchetype = entityManager.CreateArchetype( typeof(LocalTransform),typeof(RenderMesh),typeof(LocalToWorld));
         
            //Entity entity= entityManager.CreateEntity(entityArchetype);
            NativeArray<Entity> entityArray = new NativeArray<Entity>(1, Allocator.Temp);
            entityManager.CreateEntity(entityArchetype, entityArray);
            //entityManager.SetComponentData(entity,new levelComponent{level =114514});
            for (int i = 0; i < entityArray.Length; i++)
            {
                Entity entity = entityArray[i];
                entityManager.SetComponentData(entity,new LocalTransform(){Scale = 3});
                entityManager.SetSharedComponentManaged(entity,new RenderMesh() {mesh = mesh,material = material});
            }
 
            entityArray.Dispose();
        }
}

RenderMesh isn’t actually used at runtime. Instead, you need a whole mess of components.
https://docs.unity3d.com/Packages/com.unity.entities.graphics@1.0/manual/runtime-entity-creation.html

2 Likes

Oh,It seems that UnityECS is developing a bit quickly.The old Tutorial dosen`t work.Thanks