How do i set collision on sword for only when i am swinging it at an enemy

hey everyone i am having a problem with the melee weapons collsion setup, i have an enemy that i have a behavior tree set up on an he attacks me , but my weapon collides and kills him before i swing my weapon, i am wondering how do i make my weapon collide only when i swing it at the enemy.

Trying using an anim notify in an anim montage.

Using the animation blueprint and anim notify events you should be able to set so the sword only has collisions while the animation is playing.

Yep good idea. Although for my own personal use I like using anim notifies as then things dont collide on the “ramp up” section of my animations.

i tried to set up something like that with enable and disable collsion nodes but did not work the way i set it up, could you be more specific about witch graph to use the bool and how to set it all up, im new at this and the only thing that helps is step by step tutorials. and havnt been able to find anything on this subject.

can you be a little clearer on how to set it up, im kind of new to unreal, any way you could post the some pics of the set up also?

It’s hard to answer your question without knowing how your specific combat system works, i.e. how you’re applying damage to your enemies.

To set an animation notify, open your animation blueprint, go the animations tab, and open your attack animation. There you’ll see a horizontal bar that says “Notifies”. RIght click on frame and select Add Notify > New Notify and name it whatever you like. I would create one notify somewhere at the start and another towards the end.

You can then call these events in your animation blueprint’s event graph and do whatever you like. In order to get or set a variable in your character blueprint, you’ll need to get the animation blueprint’s pawn owner and cast it to your character blueprint.

Can you post a screenshot of your animation blueprint event graph?

I am using my sword to apply damage, it is set to hit on Event Begin Overlap i think i can figure this out now tho i will try it in a few, but im thinking with my set up i would have cast to my sword blueprint and set the the collision to enabled, and set my default collision on the sword blueprint to no collision… is that correct?

i tryed to set it up casting to my sword blueprint and then using enable collision node and it doesnt seem to work.

i tryed to set it up like this and a few other ways , but could not figure anything out, i am using the basic mixamo character adam sword slash, animation as attack, just trying to get a working set up before i go and make my own character.

cant seem to find weapons collsion active nodes, or the reset melee swing nodes, and is the first cast to node to your character? because when i tryed to set it up that way it said the variable reference wasnt compatible, but when i cast to my sword blueprint it will let me connect the nodes.

i tryed using set collsion, not working unless i am doing it wrong, screen shot is above how i set it up. i can set up the function if i need to i just relized it was a funtion a few seconds before you answered back, i have an experience system and damage system and everything all set up i know how to use unreal a bit but this and animations is what really irritates me it seems like it should be so easy but its really halting my progress.

Make use of breakpoints to debug your blueprints. (Right click on the node and add breakpoint). You may notice that your pawn owner is not a steelsword (I could be wrong I dont know your blueprint set up). Give the pawn a variable reference to the weapon itself, cast to the specific pawn class then get that variable off the cast return, then set its collision directly.

The screen shot is taken directly out of my game which has been a year long project. Basically I call a function on the weapon blueprint itself which enables its collision (I do this because of other custom implementation). Im pretty sure you could just enable collision directly here in the animBP.

Yes via socket to the hand bone. Do something like spawn actor of class “sword”(your weaponBp) > store this actor to variable “weapon” > attach actor to component(charactermesh) > then use that weapon ref in the animBP as well for collisions.

Ategig is correct, the animBP pawn owner is probably your character so you can’t cast to the sword BP. The best way to handle that is probably to create a reference to the sword in your character BP.

They are functions I have made? I think you should probably take a look at a few basic blueprint tutorials before you take this on. Melee weapon systems are quite complex.

And yes the first cast node is to my character. It gets the weapon variable out of my character and those custom functions are on my weapon. Just use “set collision” instead as you do not have my custom functions.

Either the character BP or the animation BP, yes. You should be able to grab the variable that is holding the reference to your sword from either.

Another way to approach this would be to use the boolean method I was referring to. Set a boolean on your character attack and then check that boolean on the overlap event. If the overlap event triggers without your character attacking, nothing happens. You can then use an animNotify to change the boolean back to false at the end of the animation.