#Parent component removed for unknown reasons

1 messages · Page 1 of 1 (latest)

olive vine
#

Some quick background, I have block entities which will always have a parent so that their position is relative to the parents position. I have a simple authoring script for the blocks:

public class BlockAuthoring : MonoBehaviour
{
    public class BlockBaker : Baker<BlockAuthoring>
    {
        public override void Bake(BlockAuthoring authoring)
        {
            var entity = GetEntity(TransformUsageFlags.Dynamic);
            AddComponent<Parent>(entity);
        }
    }
}

I also have a DefaultVariantSystem to sync the Parent component with clients:

[GhostComponentVariation(typeof(Parent), "NetworkParent")]
[GhostComponent(PrefabType = GhostPrefabType.All, SendTypeOptimization = GhostSendType.AllClients)]
public struct NetworkParent : IComponentData
{
    [GhostField] public Entity Value;
}

internal sealed partial class DefaultVariantSystem : DefaultVariantSystemBase
{
    protected override void RegisterDefaultVariants(Dictionary<ComponentType, Rule> defaultVariants)
    {
        defaultVariants.Add(typeof(Parent), Rule.OnlyParents(typeof(NetworkParent)));
    }
}

When this prefab entity is created it does not have the Parent component, unless I also add a Rigidbody to the GameObject its being baked from (See images, first one is without rigidbody attached, second one is with rigidbody attached).
I could add the component when actually instantiating the entity, but I need it in the prefab so that a client will have the component when the server instantiate the prefab.

Of course I could for example add a tag component and then have a system manually adding the Parent component to all entities with the tag, but I'd like to understand why the Parent component is not baked in seemingly for no reason.

olive vine
#

The closest of what I have to achieving what I want is adding a Physics Body from the optional samples of unity physics, and setting the motion type type to static (This only adds the PhysicsWorldIndex component to my entity). Then having a system that removes the PhysicsWorldIndex from any block entity.

#

Still seems like a very jank solution