I’m working on a fighting game in Unreal Engine 4 using Blueprints. I have two instances of the same character Blueprint (lucien_char) in the level.
I created a custom event called TakeDamage inside lucien_char, which is supposed to reduce health when the character is hit.
In the hitbox overlap logic, I try to call TakeDamage on Other Actor, but it seems like the event is being triggered on the attacking instance instead of the one that was hit.
I tried checking Other Actor ≠ Self, and even tried casting, but the event still damages the attacker.
Observation: The custom event TakeDamage does not appear as callable on Other Actor unless I cast it, which I want to avoid since I need this to work across multiple character types. And casting doesn’t solve the problem whatsoever.
Question: How can I make sure the TakeDamage event is called on the correct instance (the one that was hit), without relying on casting?
My suggestion would be using two different classes (blueprint names) for testing. I’m not entirely sure if overlaps will do the trick here. I believe what could be happening is that both overlaps trigger at the same time (you hitting the target, and the target hitting you too via their overlap).
To be fair I’m not exactly sure what would be the best approach in a fighting game, perhaps physics volumes + hit events could work here a bit better.
Anyways, I invite you to have a look here (unreal documentation) . Have a look at the built in damage dealing events. You can use that instead of your custom Take damage event.
You would use Apply Damage as you do now and then on the one receiving the damage Event Any Damage will be run (you can verify it with print string or break point). This is where your change of health would be (or you can run your existing event of it).
In regards to your observation, you cannot directly access things that are not part of parent class (eg. your variables/functions/events/macros/components), only the ones that are inherited.
This is where casting comes in, it does give you a hard reference to a specific actor (of class - cast to yourBlueprintName). You can then use said reference (blue pin) to make changes in that one specific actor or call events/function etc. To avoid repeated casts you can promote the output of cast to a variable and use this variable with your cast target, as long as it’s valid.
If you have some time, try looking into using interfaces for communication between classes, once you get comfortable with casting.
Last Question: I would try using the instigator(controller responsible for dealing damage) and/or damage causer (this could be a projectile or explosion) pins to carry out != checks.
Use some debug print string or see exactly what is happening and in what order.
I don’t have an example for melee combat I could share here, perhaps someone else will be able to provide one.