Hello everyone,
i am looking for a way to spawn a couple of Entities, but keep them invisible, until a certain point in time later on. It is not a huge amount, so adding the disable-component and removing it is a possibility, but since I have the opportunity to spawn them all at once, with one structual change, instead of 8 for example, I wanted to do that.
The magic seems to be:
ecb.SetComponentEnabled<MaterialMeshInfo>(instance, false);
But I get the following Errors:
Unfortunatly, the error messages, nor the call-stack do not tell much about what is happening.
So, here is the complete code:
public void OnUpdate(ref SystemState state)
{
var ecb = new EntityCommandBuffer(Allocator.Temp);
float distanceFactor = 1.0f;
foreach (var prefab in SystemAPI.Query<RefRW<StationPrefabComponent>>())
{
if (prefab.ValueRW.Spawn)
{
foreach ((var transform, var entity) in SystemAPI.Query<RefRO<LocalTransform>, RefRO<ShipOrientationComponent>>())
{
Entity instance = ecb.Instantiate(prefab.ValueRW.Value);
ecb.SetComponent(instance, new LocalTransform
{
Position = prefab.ValueRO.Position,
});
float3 distanceVector = (transform.ValueRO.Position - prefab.ValueRO.Position) * distanceFactor;
ecb.AddComponent(instance, new TimerComponent
{
Timer = math.length(distanceVector),
});
ecb.AddComponent<GhostOwner>(instance);
ecb.SetComponentEnabled<MaterialMeshInfo>(instance, false);
}
prefab.ValueRW.Spawn = false;
}
}
ecb.Playback(state.EntityManager);
ecb.Dispose();
}
}
I am incredibly sure, that the line ecb.SetComponentEnabled(instance, false); causes the shown errors, since removing them, removes the error.
Is there a simpler way to deactivate rendering on create and later activate rendering back?