I hope to dynamically adjust the scale and position of the prefab when in the incubation pipeline. I use PostTransformMatrix to achieve this function. However, I find that for the entity created using the prefab, the default position of its child entity is initialized from the prefab, but the scale is not. Why is this?
here is my code
private void SpawnTopPipe(PipeConfig config, float yOffset) {
float y = yOffset + config.pipeDistance * 0.5f;
float x = config.enterX;
var entity = EntityManager.Instantiate(config.pipePrefab);
EntityManager.SetComponentData(entity, new LocalTransform {
Position = new float3(x, 0, 0),
Rotation = quaternion.identity,
Scale = 1f
});
var childs = SystemAPI.GetBuffer<LinkedEntityGroup>(entity);
foreach(var child in childs){
if(EntityManager.HasComponent<PillarTag>(child.Value)){
var transform = SystemAPI.GetComponentRW<LocalTransform>(child.Value);
float scale = transform.ValueRO.Scale;
var scaleMatrix = float4x4.Scale(0.5f,2,0.5f) * scale;
SystemAPI.SetComponent(child.Value,new PostTransformMatrix{
Value = scaleMatrix
});
}
}
}
my prefab (top) and the run effect (bottom)
It can be seen that the position is the preset position (0, 1, 0) in the prefab. However, the final value of the scale is (0.5, 2, 0.5) instead of the expected (0.25, 2, 0.25).
