Wanted some opinions on ways to set up triggering “on-kill” effects. In short: The player can have abilities that trigger effects whenever they shoot and kill an enemy. I’m also looking to extend abilities to enemies as well, so can’t just hardcode a player reference.

Currently I’m doing it like this:

  • Enemy signals that it died -> the bullet receives this and signals that it killed Enemy -> the player’s weapon receives this and signals that it’s bullet killed Enemy -> the player receives this and triggers it’s on-kill abilities.

It simultaneously feels like a good way to go about it but also a long mess. The other option I’ve considered is:

  • Each bullet has a reference to it’s owner (eg. player). When an enemy dies to a bullet, it looks to the bullet’s owner reference and tells it to trigger it’s on-kill effects.

This way is a lot simpler to write, but is error prone eg. In cases where the bullet’s owner is killed while their attack is mid-air.

Thank you all!

  • Bezier@suppo.fi
    link
    fedilink
    arrow-up
    7
    ·
    8 months ago

    Definitely the latter. Rube goldberg machines will become much more error prone. The more steps you can simplify out, the better.

    You can write a simple guard in case player has died:

    if !is_instance_valid(player):
        return
    
    player.onkill()