#need help with entity component not being found

1 messages · Page 1 of 1 (latest)

radiant gyro
#

for some reason the code within the entityDie event is not running properly. It is outputting false when checking if my entity has the projectile component. The rest of the code works as intended except for the hasComponent method. Does anyone know why this is happening and how to fix it? (file names are in comments)

  // gun.js

   // projectile is zl:shotgun_bullet
   // zl:shotgun_bullet json file has projectile component 
        const bullet = player.dimension.spawnEntity(projectile, player.getHeadLocation());
        bullet.getComponent("projectile").owner = player;
        bullet.getComponent("projectile").shoot(player.getViewDirection());
//index.js

world.afterEvents.entityDie.subscribe(async evd => {
    const target = evd.deadEntity;
    const attacker = evd.damageSource.damagingEntity;
    world.sendMessage(`${attacker.typeId}`);  // outputs zl:shotgun_bullet
    world.sendMessage(`${attacker.hasComponent("projectile")}`);
    // outputting false
})
twilit ice
#

like this

    world.afterEvents.entityDie.subscribe(async evd => {
        const target = evd.deadEntity;
        const attacker = evd.damageSource.damagingEntity;
        const projectile = evd.damageSource?.damagingProjectile
        world.sendMessage(`${attacker.typeId}`);  // outputs zl:shotgun_bullet
        world.sendMessage(`${projectile.hasComponent("projectile")}`);
        // outputting false
    })```
radiant gyro
twilit ice
#

o

twilit ice
radiant gyro
#

Im doing it the old way. I cant be bothered to fix it

twilit ice