Destroy entity in one system and get error in other.

Hello, I destroy target entity in this system (bullet hit bot and both should be destroyed)

using Unity.Entities;
using Unity.Mathematics;
using Unity.Transforms;

public class DestructionSystem : ComponentSystem
{
    private EntityManager entityManager;

    protected override void OnStartRunning()
    {
        entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;
    }

    protected override void OnUpdate()
    {
        Entities.WithAll<Destructor>().ForEach((Entity vilian, ref Translation vilianTrans, ref Destructor destructor) =>
        {
            float3 vilianPos = vilianTrans.Value;

            Entities.WithAll<Destructable>().ForEach((Entity victim, ref Translation victimTrans, ref Destructable destructable) =>
            {
                if (math.distance(vilianPos, victimTrans.Value) < 1)
                {
                    entityManager.DestroyEntity(vilian);
                    entityManager.DestroyEntity(victim);
                }
            });
        });
    }
}

But in the other system I have code like this

public class AttackSystem : ComponentSystem
{
    protected override void OnUpdate()
    {
        Entities.WithAll<BehaviourStateAttacking>().ForEach((
            Entity entity,
            ref Translation translation,
            ref Rotation rotation,
            ref BehaviourStateAttacking behaviourStateAttacking,
            ref Turning turning,
            ref ShootTimer shootTimer
            ) =>
        {
            float3 myPos = translation.Value;
            quaternion myRot = rotation.Value;
            float turningSpeed = turning.TurningSpeed;
           
            float3 turgetPoint = World.DefaultGameObjectInjectionWorld.EntityManager.GetComponentData<Translation>(behaviourStateAttacking.AttackTarget).Value;

In the last published line I have an error that sais “ArgumentException: A component with type:Translation has not been added to the entity.”
how to fix the issue?

The entity you destroyed is going to be the same as your attack target, behaviourStateAttacking.AttackTarget

An entity that doesn’t exist doesn’t have a translation value.

Thank you, capitan. But how do I fix the error, when I destroy entity in one system and try to get entity in the other? What kind of if_entity_exist do I have to use?

Most of the time you’re using entity references you need to check it has the component first (HasComponent) and handle that.

Thank you.

if (EntityManager.HasComponent(behaviourStateAttacking.AttackTarget, typeof(Translation)))