Entity Prefab/Mesh change?

Hi folks,

all the best for this new year.
I have been toying around with this, but I was not successful.
What I want to do is that when something happens to an entity, it changes its form.

I have 50 cube entities and when one of the cubes is reaching something, or hitting something, it changes to a sphere.
(PostUpdateCommands?)

Does anyone have an idea?

Thanks in advance.
Slarti

Somebody has an idea please?

hi Slarti,
I think you have several options to do what you want, the first two ideas that come to my mind are:

  1. switch from a MeshRenderer scd to another every time an entity triggers your event.
    or
  2. instantiate a new entity with a different MeshRenderer scd and fill it with the old entity components.

One possibility could also be to have a Parent Entity that holds all data and connect the visual of the Cube/Sphere to that parent entity. Then when the parent entity reaches the trigger make it delete the current visual and spawn in the new visual as a child.

1 Like

In my project I’ve gone the route of swapping the RenderMesh SCD. I store the RenderMeshes of all my converted prefabs in a system.

This works well enough, but because RenderMesh is a SCD, it can’t be stored in a NativeHashMap or other native container. For now, I’ve just put these in a normal Dictionary, but I’ve heard that the unsafe containers may also work here. Curious if anyone has a different solution to this.

I’ve also considered the approach of storing the mesh as a child entity, but I didn’t want to pay the cost of the transform system for no reason. I also find that a flatterer hierarchy is easier to reason about in ECS. But I think this can still make a lot of sense if you have a bunch of components that map 1 to 1 with your mesh and you want to swap all of them at once.

1 Like

Thanks all for the answers. I will try this.
@StickyMitchel could you share some code, how to address and replace the parent/child, please?
Thanks

This sounds resenable.
I woul also try similar alternative way, where parent having two children entities, mesh0 and mesh1.
Then depending on parent state, setting Disabled component, on corresponding child.
Optionally DissableRendering component, but then transform is still calculated.

Setting children is done automatically, when setting parent. But few conditions are to be met, while components are required. I. E. LocalToWorld. Local To Parent, rotation, position and I think few others.