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:
meshRenderer = new RenderMesh();
GameObject shipPrefab = Resources.Load<GameObject>("Prefab/ShipPrefabGameObject");
shipEntityManager = World.DefaultGameObjectInjectionWorld.EntityManager;
shipEntityPrefab = shipEntityManager.CreateEntity(typeof(Prefab),
typeof(RenderMesh), typeof(RenderBounds),
typeof(LocalToWorld), typeof(ShipEntityComponent));
meshRenderer.mesh = shipPrefab.GetComponentInChildren<MeshFilter>().sharedMesh;
meshRenderer.material = shipPrefab.GetComponentInChildren<MeshRenderer>().sharedMaterial;
shipEntityManager.SetSharedComponentData(shipEntityPrefab, meshRenderer);
shipEntityManager.SetComponentData(shipEntityPrefab, new RenderBounds { Value = meshRenderer.mesh.bounds.ToAABB() });
NativeArray<Entity> shipsEntityArray = new NativeArray<Entity>(ships.Count, Allocator.Temp);
shipEntityManager.Instantiate(shipEntityPrefab, shipsEntityArray);
It would be awesome to hear some thoughts and see some code.
Thanks in advance.
Slarti.