#Custom PostBakingSystem cannot find Child Entities

1 messages · Page 1 of 1 (latest)

frosty basalt
#

I’m trying to get the PhysicsJoints that Unity creates if I add a ConfigurableJoint to an Entity, so Unity will create 2 entities as a child with PhysicsJoints, I then created a PostBaking System, and in it I put a Debug to check how many childs entities there were inside these Components, and it shows 0, even though I can clearly see them in the Entities Hierarchy, here is the code below and the images


using System.Diagnostics;
using Unity.Burst;
using Unity.Entities;
using Unity.Physics;
using Unity.Transforms;
using static SyncPhysicsJointAuthoring;

[WorldSystemFilter(WorldSystemFilterFlags.BakingSystem)]
[UpdateInGroup(typeof(PostBakingSystemGroup))]
partial struct SyncPhysicsJointBakingSystem : ISystem
{

    //[BurstCompile]

    public void OnUpdate(ref SystemState state)
    {
        foreach (RefRW<SyncPhysicsJointComponent> syncJoint in SystemAPI.Query<RefRW<SyncPhysicsJointComponent>>())
        {
            Entity mainEntity = syncJoint.ValueRO.thisEntity;

            UnityEngine.Debug.Log($"Entity {mainEntity} has Child: {state.EntityManager.HasComponent<Child>(mainEntity)}");

            if (state.EntityManager.HasComponent<Child>(mainEntity))
            {

                DynamicBuffer<Child> childBuffer = state.EntityManager.GetBuffer<Child>(mainEntity);

                int jointCount = 0;
                UnityEngine.Debug.Log($"Checking entity: {mainEntity}");

            }
        }
    }
}

#

And I did add [WorldSystemFilter(WorldSystemFilterFlags.BakingSystem)] [UpdateInGroup(typeof(PostBakingSystemGroup))]

mighty forum
#

Child buffer is only created at runtime

#

it's a cleanup component

    public struct Child : ICleanupBufferElementData
    {
        /// <summary>
        /// A child entity
        /// </summary>
        public Entity Value;
    }```
#

which means it can't be baked or used during baking

#

it's added at runtime in the ParentSystem

frosty basalt
mighty forum
#

I'm just commenting on your above code which is reading the child buffer in a baking system

frosty basalt
mighty forum
#

LinkedEntityGroup should have them all

frosty basalt
mighty forum
#

It can have other things in there though, so if you want to know it's actually a child in the hierarchy vs just a linked entity you'll need to check for the Parent component and make sure it points to the root entity

#

(The parent component is how the Child buffer is built)

frosty basalt
#

For now I'm getting the component during runtime

frosty basalt
mighty forum
#

LEG will always have the root entity in it

#

LEG can also have other entities linked to it that aren't in hierarchy

#

via things like
baker.CreateAdditionalEntity()

#

these entity will be created/destroyed linked to the root entities lifecycle

#

but it isn't in the transform hierarchy

#

they might not even have transforms