How can i make it so my weapon must swing thru a box to break it?

so currently, im trying to make breakable boxes that you must hit with your weapon to break them, im using begin overlap on a box collison, im wondering if there is any better way of doing it. or maybe disabling the weapons hitbox until attack button is pressed and then activate the hitbox for a delay before re-disabling it?
thanks for any help, will provide some screenshots of whatever is needed.

This should be fairly easy to achieve but you need to provide a little more information cause right now its just guess work. Are you using a destructible mesh? if you are then you just need to tinker with the settings and a few things in your weapon blueprint, or maybe your using some kind of pre-rendered animation to destroy your object? provide this information and some screenshots of how you’ve setup both the object your trying to destroy and the blueprint with your weapon and we should be able to help you out.

i am not using a destructible mesh because im not sure how to use one of those. what im using is a cube basically with a box collision on it, thats basically all the code i have for destroying the crates. from there on the weapon i just have another box collision adjusted to the size of the end of the weapon with a Tag Component on it.

hey this sounds like what im looking for but how would i go about this, since my attack code is in my thirdperson blueprint, i added the one boolean for IsSwinging but then how would i go about linking it to my boxes overlap check?

hey roboshmeckle,

it sounds like both ideas are valid ways of doing what you’re looking for. The only advice I can think of is if you want to break the box only when you swing, have a boolean set to true when you swing and in the boxes overlap check, only execute if that boolean is true. You dont want to be able to walk next to your boxes and have your sword overlap and the boxes break. Unless you do haha let me know how it goes for you

Alright I’m not sure about how tags work but this is how I set it up for my own game, but I set almost everything up within the WeaponBP so yours will probably look a bit different, and you’ll need to imagine the ZombieBP is your crate.

Now between your cast to wrench_BP and your destroy event you’ll need to set a branch with a boolean from your Wrench_BP as a condition, my boolean is Weapon Can Collide, when the weapon is swinging it should be true so that it can move on to destroy the crate, when the weapon isn’t swinging it should be false and nothing will happen.

Hope that helps.

Alright I’ve done something similar for my own game, I’ve just posted an answer.

i feel like im stupid but i cant figure it out lol, i have it set up how urs is, its in the weapon blueprint, on the hitbox, but its still colliding while walking and swinging instead of just swinging

You’ve probably missed something, can you provide some more screenshots, both from the weaponBP and the crate.

sure thing, on the weapon blueprint i went back to component beginoverlap because i got frustrated for a minute with the boolean, but if you could explain how to set that up a little more that would be appreciated maybe in discord or skype or something so i could screenshare, here is screenshots, i dont have anything in my crate blueprint event graph so thats just the components i have for the crate

I don’t see a branch between cast to crate_destructible and the destroy event, You need put a branch between them with (Is Swinging) as a condition so it knows to destroy the crate only when the weapon is swinging.

so this is my weapon blueprint now, when i swing the crate doesnt break at all now. what am i doing wrong still lol, sorry this is taking so long. ![alt text]

Show me a full screenshot of where the is_swinging boolean is being set to true or false.

thats probably the issue, i dont have any code in the event graph that says its true or false, just it ticked. but now, its breaking when i run into them

For a quick test you can get the code from your Character BP since a is_swinging boolean is already setup there. Within your weaponBP cast to characterBP with get player character as object, then get the is swinging boolean from characterbp and use that as a condition for the branch thats connected to destroy, you’ll probably have to clean it up later due to things like momentum.

I’ll be off for a while so I’ll check again later to see if you’ll get it working.

I just caught up on what you’re attempts in the other comments. Where is your swing event? Can you post a screenshot of the swing blueprint code? Also, is there an animation for your swing? A quick/dirty way to do this would be for example:

  • First set a is_swinging boolean in your weapon BP blueprint to false by default.

We need a way for your character to get this boolean from your weapon BP. Assuming your weapon is a child in your character BP, we can get direct access to this variable. So we want to do this.

  • Let’s say Left Mouse Button pressed swings. When Left Mouse Button is pressed, weapon BP’s is_swinging should equal true.
  • On your Left Mouse Button(or whatever event triggers your swing) event, you want to get Wrench_BP(? if thats the weapon) and then get the is_swinging bool we set up. Set it to true.
  • When Left Mouse is released, we do the same thing except is_swinging = false.

Your next step is to figure out how to get is_swinging when your weapon is overlapping. This is assuming you’re working with a hitbox in the weaponBP.

  • In your On Begin Overlap you want to Branch using the is_swinging.
  • If true(which we set it to true using the character BP), we can now add in the component tag with branch and cast Other Actor to your object you want to destroy, and call the destroy event.

The only thing you need in your crate BP is the destroy event. Every thing else is in the weaponBP or characterBP.

A more complicated and correct way is to set up notifies in your swing animation. If you need help with that I can help you with that to.

okay sounds cool, ill definitely try this out. i can post a few more screenshots if you want, and i dont think i have my weapon as a child, what i did for it was create a socket on the skeleton and then when the game starts the weapon spawns in the hand.

also i didnt see the first sentence about asking for my swing animation, im assuming you’re talking about like my button press line of code so here is that, just minus the IsSwinging Set in the beginning .

It looks like you have your is_swinging in your characterBP. And since youre attaching your weapon to a socket, I made a similar setup.

You want to have your character as the owner so we can get your is_swinging bool later. The delay in my left mouse button is to act as your animation. Im also saving the weapon after creating it to a variable so I can access it later if I want.

Now In the weaponBP, i do my overlap check.

I have it to check on event tick because I dont have anything else to check the overlap with. Right now, it’ll be checking if I’m overlapping with any object including my character when I attach it. Thankfully we setup the is_swinging to only be true if I click. The print string will only show when I click my left mouse and until the delay is over, setting is_swinging false. Obviously, you want to replace my print string with you’re destroy event and don’t add in the event tick. Let me know if this works for you