Spawn Entities from Prefab with different scale and color

Hi there,
I quite new to ECS / DOTS, so first of all, apologies if the question I am about to ask is already answered.
My use case - I would like to create I bunch of entities from the existing prefab and for each entity, I would like to set:

  • Position
  • Scale
  • Color
    Now, I already saw how I can set the position:
manager.SetComponentData(rotatingCubeEntity, new Translation { Value = new float3(posX, 0.0f, posZ) });

However, I have issue to find how to set scale and color.
For scale, I can see, I can create an entity archetype and to include Scale, however, looking at Unity.Transforms.Scale struct, I can see just a single Value, so it is not clear to me how I can scale in 3-dimensional world.
Regarding the color - the way I found, the color is set is basically like that:

RenderMesh newrend =  manager.GetSharedComponentData<RenderMesh>(rotatingCubeEntity);
newrend.material.color = gradient.Evaluate(UnityEngine.Random.Range(0f, 1f));
manager.SetSharedComponentData(rotatingCubeEntity, newrend);

however, with this approach, since the renderMesh is shared among all entities, I set the new color to all entities. So basically I have all entities in the same color.
I would appreciate either a scripting example or reference to the existing one.
Thanks

I’ve tried one (sngdan’s) of the implementations from here, with significant success: 200k dynamic animated sprites at 80fps

I haven’t gone back to see if Rendering.Hybrid is yet competitive with Graphics.DrawMeshInstanceIndirect.

Regarding the scale you should read this, the short version is that you probably want the NonUniformScale component. Per-instance color is more complicated. The hybrid renderer only supports per-instance data in HDRP right now and it’s most definitely not beginner friendly to get it working. See this thread for more information.

Thanks, @digitaliliad and @Sarkahn_1 for your answers. I found the latter thread very informative since I am also using LWRP / URP in my project - something I forgot to mention. So basically, ECS in terms of dynamic rendering for URP is way too far from being implemented. Am I correct?

Seems that way yes. Last I heard is we can expect to hear some news on that front sometime in the next few months, but no more details than that.

1 Like