Hi there, i had some troubles instancing some entities of my scene, due to the children were not copied. I found out, that the EntityManager.Instantiate Method uses the LinkedEntityGroup, that was not there.
My entities get a Disabled component directly in the Baking, so they are not processed by the usual system, that adds that afterwards. The Entities just have Parent component and children buffers, but no LinkedEntityGroup.
As a workaround, i could do that before instanciating them on runtime, but it felt better to have that in the bake.
So my first question: Is this a possible bug, or is there any reason, why the LinkedEntityGroup is not part of the default Baking?
As a workaround, i tried to create a BakerSystem, that fixes this. I found, that there are no Children in the Baker, so i tried to figure out how to make my System running after the ones who creating the child buffers, but i couldn’t figure out where this is. (seems not visible in the Systems Window? or is this done separate?)
So my second Question: Any Docu about the BakerSystem with some useful examples?
Ps.: My first try was to use EntityManager.CreateQuery(…).toEntityArray() That failed with a nullpointer, so seems at least need some docu what can be used there
However, my Workaround for that was now to add also the childs by myself, is there a better way?
[WorldSystemFilter(WorldSystemFilterFlags.BakingSystem)]
partial class FixLinkedGroupEntityBakingSystem : SystemBase {
protected override void OnUpdate() {
Entities.WithStructuralChanges().ForEach((Entity entity, in Parent parent) => {
var children = EntityManager.GetOrAddBuffer<Child>(parent.Value);
// To see when we don't need the workaround anymore, we add this logging.
var c = children.GetEnumerator();
while (c.MoveNext())
if (c.Current.Value == entity) {
Debug.Log("Seems we don't need to do this anymore. Child aready exists.");
return;
}
children.Add(new Child() { Value = entity });
}).Run();
Entities.WithStructuralChanges().WithNone<LinkedEntityGroup>().WithAll<Child>().ForEach((Entity entity) => {
var buffer = EntityManager.AddBuffer<LinkedEntityGroup>(entity);
foreach (var linkedChild in EntityManager.FindAllChilds(entity, Allocator.Temp).DisposeToSimpleArray())
buffer.Add(new LinkedEntityGroup() { Value = linkedChild });
}).Run();
}
}