Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only.

    Please, do not make any changes to your username or email addresses at id.unity.com during this transition time.

    It's still possible to reply to existing private message conversations during the migration, but any new replies you post will be missing after the main migration is complete. We'll do our best to migrate these messages in a follow-up step.

    On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live.


    Read our full announcement for more information and let us know if you have any questions.

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:
    5
    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,349
    TKOW and Anthiese like this.
  3. TKOW

    TKOW

    Joined:
    Mar 6, 2018
    Posts:
    5