Download

Long-Term Player Combat Logic

Hi guys,

I find it easy to take one weapon in blueprint and set it up so that my characters can fight with that weapon, usually with 1-2 different attacks at most, but I’m currently undertaking something much larger in scope.

I’m looking for input on how you guys would go about setting up 2-3 attacks per weapon, for ~20 weapons. The type of weapons would be ranged (projectile), melee, and traps. Each weapon would have a unique set of animations to go with the type of weapon, and some would require two hands and a full body swing while others would be smaller and interchangeable with other smaller weapons.

Like I said, I’ve checked out the numerous examples and tutorials on how to set up an attack and deal damage, and I got that replicating over the network rather easily. I’m more interested in hearing how you’d categorize weapons or attack types (in your character BPs, custom weapon/item BPs, and animation BPs) and what parts of the pipeline would you try to abstract into a single gateway rather than keeping it unique to the weapon.

Here’s an example I’m stewing over right now: Should I have a boolean in MyCharacter BP that signifies “IsAttacking?” or should I break that apart into more detailed logic, such as “IsAttacking_Spear?” or “IsAttacking_Range?” (though our spear can be thrown or jabbed)

Thanks for the potential input!

You can set up you key bindings in the project settings tab and then do everything else in either blueprints and/or using your characters state machine. It’s all laid out in the ‘Third Person’ video series on the Unreal Engine youtube page. That tutorial shows you how to set up a state machine for ‘is jumping’, all you have to do is set up a state for say ‘is using this gun’ - then set up the appropriate key bindings for the various attacks and so forth.

Yeah I’m fully aware of that and have already done it for punching, kicking, spear throwing, and spear thrusting. It’s just becoming unwieldy to manage so many weapons/attacks/states. I’m curious to know if anyone has any thoughts on how to adapt the process to a larger scale that doesn’t end up in blueprint spaghetti (or minimizes it).

What I do is I just design the full attack logic based on simple events and flags (i.e. bInCombo, EventAttackPressed), and then use a Switch On Enum to route the significant attack commands to separate outputs based on a “Weapon” Enum that contains all possible weapons for the character to have equipped.

Then I just use Graph Collapsing to make each weapon’s unique logic into something separate and manageable.

Looks like this:

The reason it pays to do it this way, but to use common flags like “is Attacking” rather than “is Attacking Spear”, is that you can drive your state machine in a sane way. Working from the assumption, of course, that your states wouldn’t change for attacking, and all that would happen is you’d play different Montages for each attack, you just set each weapon’s montage to use the same set of slots (e.g. MeleeGROUND, MeleeAIR, ReloadGROUND, ReloadCROUCH, whatever) and use different “Montage Play” commands within each collapsed graph.

The advantage to using collapsed graphs rather than something simpler is it makes weapon logic easy to modify; if you want one weapon to work by tapping melee repeatedly, but another to work by holding and releasing the attack command, you can use these separate graphs to construct totally different logics, and as long as they can all operate using basic montages, you can continue to drive your state machine in the same fashion.