Hi, brand new to unreal development so this is very basic I’m sure. I couldn’t find an answer online or in thsi forum so sorry if the answer is here already. Basically I’ve created an attack flow in my character blueprint. i wanted to reuse the attack function for various attack types and then use variables to determine the different thigns such as reach and attach power etc.
My issue is the setters at the beggining. I’m duplicating the setters for each attack type which will obviously get worse as I add different attack types. How can I have 1 line of setters here and depending on which enumerator was used to call them (e.g. which attack type) set the values differently?
Hey! Doing it this way will definitely make your graph hard to manage later. Here are 3 ways to optimize this, from simple to professional:
The “Select” Node (Easiest): You don’t need multiple execution lines. Use only one Set node for each variable (e.g., Attack Power). In the input pin of that Set node, plug in a Select node. Connect your E_AttackType to the Select node — it will automatically create pins for “Punch” and “Kick”. Now you can just type the values directly there.
Using a Struct: Create a User Defined Structure with all your parameters (Power, Distance, Height). In your Blueprint, you can use a single Select node to switch between two versions of this entire Structure. This keeps your graph super clean with only one “Set” node for everything.
Data Tables (The Pro Way): If you plan to add 10+ attack types, use a Data Table / create a Struct first, then create a Data Table based on it. You can fill in all the numbers there like in Excel. In your Blueprint, just use the “Get Data Table Row” node and pass your Enum as the Row Name. This way, you don’t have any hardcoded numbers in your logic at all!
Method #1 is a quick fix, but #3 is what people use in real production. Good luck!
In Unreal Engine (Blueprints), repetition when setting variables from multiple execution paths is a very common issue. The best way to reduce this is to centralize your variable assignments into a single execution path instead of setting them multiple times.
Recommended approaches:
1. Use a single “Set Variables” point (merge execution paths)
Instead of setting variables inside each branch, route all execution paths into one final node.
Set all variables in one place.
This keeps logic cleaner and avoids duplication.
2. Create a Function or Macro
Put all variable-setting logic into a Function or Macro.
Call it from different paths.
This is the best solution if the same logic is reused often.
3. Use a Struct (advanced but clean)
Combine related variables into a Struct.
Pass the struct around and set it once.
Helps especially when you have many variables.
4. Use “Select” nodes before setting
Instead of branching multiple times, decide values using Select nodes.
Hey @Schnedicles , I’m glad you found this helpful and while the marked solution is correct, just be aware that both interactions are AI, you can tell by the second one’s nonsense picture and formatting, and the language and formatting of the first (marked) one.
Also, there are many many ways to optimize a setup like yours, your method will perform well, your main concern will be editing it later, the main idea is keeping it all in once place, keep it readable (for you and your teammates) and avoiding extra boilerplate and overhead like creating struct assets and data table assets which require structs and having your project balloon in files for a function that sets a handful of floats.
My general advice is, you can keep it as is if you’re only using it as is, and if it’s not bothering anyone, and optimize as you go, don’t worry about min-maxing every line of code, keep it simple, keep it readable.
haha you got me on the formatting! English isn’t my main language, so I use tools to make my posts actually readable and not a mess. But the tech advice is mine.
I still think Data Tables are worth the effort though. If you’re planning to add a lot of attacks, it’s much better to have a system ready than to mess with code every time you want to change a few floats. Scalability is key for me, I hate cleaning up spaghetti code later.
Anyway, thanks for the input, good to see different opinions!