Hello!
I’m trying to damage a deer through my possessed Third Person Character’s BP. It feels cleaner to me than using an Event Hit in the deer’s Blueprint. I’m misunderstanding some logic to get my Branch to correctly register as “True” when the deer is hit:
You are getting every instance of the deer class in the level. The result is returned in an array. So there is an array of every deer in the level. Then you are getting the 0 index (the first index) of that array.
So, you are just grabbing some random deer. There is no way to know if that is the one you damaged or not.
Although it seems counter-intuitive, a better way to handle this is for the deer to determine how it interprets damage on its own blueprint. The way you can accomplish that is something like this:
If a hit is made from the line trace, send a blueprint interface message to the Other Actor. The blueprint interface might be called something like “Damage BPI”.
Any actors who can take damage would implement this interface.
Then, on the deers blueprint, after you have implemented this Damage Interface, you implement the interface event called something like “OnTakeDamage.”
However you want the deer to interpret damage can happen from that event.
If you do things this way, you’ll avoid problems of building a giant, impossible to maintain class that references too many others, and you’ll be able to scale your code more easily. Any actor that can be damaged just implements the interface and handles the event.
That is sounding like too much complication for a beginner, but it’s worth the time to find some youtube videos and read up on the documentation so that you can learn how to use interfaces for blueprint → blueprint communications. If you avoid it, eventually your code is going to be a giant tangle that you won’t be able to deal with.
You will also want to look into using Actor Components. That is yet another way you can make it so that you’ll be able to reuse the OnTakeDamage code all over your project in a non-destructible, flexible way.
1 Like
Thank you for the insight! Yes, I have decided to take your advice and handle the deer’s programming in its own blueprint.
I’m four months in, and frankly, I’m surprised how far I’ve come, but there’s still a lot of reprogramming in my own thinking to be effective, as you’ve shown!
1 Like
there is a lot to learn, but that’s just guarantees more fun. happy to help.
1 Like