Exception: Component has not been added to the entity Help

Hello,

My code here:

public class ResourceMouseOverSystem : ComponentSystem
{
    public struct MouseOverResourceTargetGroup
    {
        public ComponentDataArray<ResourceTypeTag> tag;
        [ReadOnly] public ComponentArray<CapsuleCollider> Collider; //why can't I just use this? when I try, collider is always null
        public EntityArray Entities;
        public int Length;
    }

    [Inject] MouseOverResourceTargetGroup resourceGroup;
    protected override void OnUpdate()
    {
        var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        for (int j = 0; j < resourceGroup.Length; j++)
        {
            var entity = resourceGroup.Entities[j];
           
            RaycastHit hit;
            var collider = resourceGroup.Collider[j];
           
            if (collider.Raycast(ray, out hit, Mathf.Infinity))
            {
                Debug.Log("I am hovering over it");
                if (!FallenBootstrap.entityManager.HasComponent(entity, ComponentType.Create<MouseOver>()))
                {
                    PostUpdateCommands.SetComponent(entity, default(MouseOver));
                    //FallenBootstrap.entityManager.AddComponent(entity, ComponentType.Create<MouseOver>());
                }
            }
            else
            {
                if (FallenBootstrap.entityManager.HasComponent(entity, ComponentType.Create<MouseOver>()))
                {
                    Debug.Log("I am removing a component");
                    PostUpdateCommands.RemoveComponent<MouseOver>(entity);
                }
            }
        }
    }
}

produces this when I mouse over the resource spherecollider:

any thoughts as to why? thanks!

On line 27 you are using PostUpdateCommands.SetComponent. Try changing this to PostUpdateCommands.AddComponent. The former is trying to set the component value and if the entity doesn’t have it attached it will throw this exception.