Search Unity

  1. We are looking for feedback on the experimental Unity Safe Mode which is aiming to help you resolve compilation errors faster during project startup.
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

A question - How to change colour or prefab of an Entity when something is happening to it?

Discussion in 'Data Oriented Technology Stack' started by Slarti-42, Feb 29, 2020.

  1. Slarti-42

    Slarti-42

    Joined:
    Jul 1, 2019
    Posts:
    25
    Hi folks,

    I hope this question helps others as well.

    I was wondering in regards to this. Some thoughts.
    Is possible to change the shared component (renderMesh, Render Bounds, Prefab)? If yes, does it change for all the Entities?

    Would it make any sense to destroy that Entity, and make a new one (new chunk with Entities that have this condition)? Or is should I tag it and change with the first question the prefab...?

    What would be the code like, please? In my code I do following to create my Entities:


    Code (CSharp):
    1. meshRenderer = new RenderMesh();
    2. GameObject shipPrefab = Resources.Load<GameObject>("Prefab/ShipPrefabGameObject");
    3.  
    4. shipEntityManager = World.DefaultGameObjectInjectionWorld.EntityManager;
    5. shipEntityPrefab = shipEntityManager.CreateEntity(typeof(Prefab),
    6.        typeof(RenderMesh), typeof(RenderBounds),
    7.        typeof(LocalToWorld), typeof(ShipEntityComponent));
    8.  
    9. meshRenderer.mesh = shipPrefab.GetComponentInChildren<MeshFilter>().sharedMesh;
    10. meshRenderer.material = shipPrefab.GetComponentInChildren<MeshRenderer>().sharedMaterial;
    11.  
    12. shipEntityManager.SetSharedComponentData(shipEntityPrefab, meshRenderer);
    13. shipEntityManager.SetComponentData(shipEntityPrefab, new RenderBounds { Value = meshRenderer.mesh.bounds.ToAABB() });
    14.  
    15. NativeArray<Entity> shipsEntityArray = new NativeArray<Entity>(ships.Count, Allocator.Temp);
    16. shipEntityManager.Instantiate(shipEntityPrefab, shipsEntityArray);
    17.  
    It would be awesome to hear some thoughts and see some code.
    Thanks in advance.
    Slarti.
     
    Last edited: Mar 2, 2020
  2. Slarti-42

    Slarti-42

    Joined:
    Jul 1, 2019
    Posts:
    25
    Would that help?

    Code (CSharp):
    1. public static void ConvertGameObjectsToEntitiesField(GameObjectConversionSystem conversionSystem, GameObject[] gameObjects, out Entity[] entities)
    2.  
     
  3. siggigg

    siggigg

    Joined:
    Apr 11, 2018
    Posts:
    247
    Slarti-42 likes this.
  4. Slarti-42

    Slarti-42

    Joined:
    Jul 1, 2019
    Posts:
    25
    just read through this. Looks good. Will give it a try. @Joachim_Ante I hope we can change Entities Prefabs on the fly.
     
    siggigg likes this.
unityunity