Destroy bullet and target on hit

Hey all,

I’m trying to achieve something fairly simple. I have a ball that I’m using as a projectile and trying to destroy other actors and itself on hit. Also, I was trying to add an effect from the BP_Effect_Explosion from the starter pack.

This is what I have so far:

Actors do not get destroyed. Collisions do happen and the barrels get knocked by the bullet

The bullet gets destroyed, right? You have that code there.

However there is no destroy for what was hit. I suggest either putting the same code on the target (on hit destroy me) or have the bullet call destroy on “other” - possibly after casting to make sure it is something you want destroyed and not a wall or something.

The bullet does not get destroy either.
On other I have the bp_barrel linked and == to the branch condition. Nothing happens :frowning:

I’m sure it’s got something to do with the physics and collisions I set, but can’t figure out what…


The issue with your branch is that you are using ==. Don’t use that for this, use Cast To instead. That will tell you if this is “any” barrel. == only tells you if it is “this specific” barrely, which it can never be while running the game.

I doubt you only want to destroy the bullet when it hits a barrel though. I recommend you CastTo the barrel, destroy that reference. Then destroy the bullet no matter what (maybe a Sequence with Cast To on first action, followed by the Destroy.)

It would look like this:

1 Like

would this be on the barrel bp? or the bullet?

if bullet, do I do it on the collision “sphere” or the static mesh itself (bullet)?

Ok, after playing some more with the collisions this actually works and it’s pretty cool.
However, is there a way to make it work for multiple targets so that I don’t have to build another event for each different actor bp that I want destroyed???

Sorry I didn’t realize you responded with a question. I know this is late, but just in case you still want a solution:

If there are certain actors that you want destroyed by bullets, then I suggest using an Interface. You would call it something like “BPI_BulletDestructible”. You could even give the interface an Event if you wanted, like “HitByBullet” or something.

Interfaces are signatures that you can use like a class to see if an instance of an object is a version of the “thing” you care about. In this case, is that actor a thing that can be destroyed by a bullet? If it casts to BPI_BulletDestructible then the answer is yes. You call DestroyByBullet on it and let that thing do whatever it does when destroyed by the bullet. If it is a gas can, huge explosion FX, if it is a wall, maybe a puff of smoke, a tree maybe it asset swaps to a broken tree and falls over, etc.

The key here is that you move the “what happens when you are hit by a bullet” to the actor itself but the bullet only knows “are you a thing I can hit that makes something happen?”

If you need some more detailed step-by-step screenshots let me know. It might be too late and you might have already solved this. Either way I will try to remember to check back here to see if there is follow-up I need to do.

That sounds super cool. The way I implemented my event was to basically add the event destroy + special effect on each destructible type of item. each with it’s own special effect. which works great. Object is hit by bullet → destroys itself → spawns special effect.
I am however, intrigued by your solution and it sounds pretty cool.
So basically, I’m creating a BPI, add an event in there called “HitByBullet”.
Then… I import the BPI in each destructible object type bp? cast to BPI? and call the event?
How do I build the HitByBullet event to branch out for each specific object/effect?
I kinda like that approach, but not sure how to implement it.
If it’s not too much of a hassle could you show me an example where the bpi would handle 3 types of objects each with its own special fx?

Interfaces don’t have code, they are like a promise to implement functions. How they work for Unreal is detailed here: UE5 Blueprint Interfaces

Let’s say you made an interface called BPI_BulletDestructible like I mentioned above. It would have 1 event: HitByBullet (you create it as a function on the interface, but any functions that lack return values automatically become events in the class that implements them).

Then, on your Barrel blueprint, you add the BPI_BulletDesrtuctible to its interface list (this is located under Class Settings).

Add the interface event to your class by double-clicking it from the Interfaces section. It is now located where your Functions and Methods are.

In that Event, do whatever you want to do (make explosion, destroy the actor, play a richochet sound, etc.)

In your bullet, instead of casting the overlap or hit (whichever you are using) to a blueprint, you cast it to your interface. This now means your bullet will call that method on any class that you implement that interface for. You want your bullet to destroy a door? Have your door blueprint implement that interface and add the code you need to destroy the door. Want it on a window?, etc. Your bullet will ignore anything not implementing that interface, so it won’t destroy everything in your scene.

Does that make more sense?

Gotcha! Thank you. I think I got it