Ways to Optimize 'do once' nodes with multiple inputs

Hello!

The script attached is working as intended - Gain health once when input 3 is pressed, and lose health when any other input is pressed. Is there a way to clean this up and allow for further executions to be performed?

I’m still new to UE4 so painfully detailed explanations are welcome.

Thanks!

Please show how you’re calling the functions. It seems confusing why you would organize them this way so I need to know more about the purpose for these nodes. For now, here’s my answer:

All of these redundant nodes can be optimized as follows: Create an [Enumerator] object in your [Content] panel and assign all of the {Texture} inputs to them. Then, in your blueprints, create a new [Function] or [Macro] with your new {Enumerator} and a {Boolean} called, “Negation”, as an {Input}.

{Sub Node 0} (Prep for your first node): Attach the function’s incoming ({Enumeration} variable) pin to the (Index) pin of a [Select] node. This will automatically populate the node with the {Enumeration} lines you created earlier. From there, you can connect the {Texture} references to each of the options on the [Select] node. That way, all you have to do is select the {Texture} from the drop-down box created by the function’s ({Enumerator} parameter) pin whenever you call the function. Take the (Return Value) pin from the [Select] node and connect it to the ({Texture} parameter) pin of the [Update HUDHead] node you will place, below.

-OR- You could forgo using the {Enumerator} variable and simply create a {Texture} parameter for the function and connect that pin directly to the [Update HUDHead] node’s ({Texture} parameter) pin.

Make a [Get Head Equip Image] node, like you have shown.

[[In Exec} node for your function]->[Update HUDHead] node with (Target) pin coming from your Get node and the (Texture) node pin coming from the function’s [Select] node or incoming parameter pin->(See {Sub Node 1}, below)->[Set {Health}] using the (Results) pin from {Sub Node 1} as the input

Create a [Make Literal Float] node (or another input variable of type {Float}) below the [Get {Health}] node as two separate, unconnected nodes.

{Sub Node 1}: [Get {Health}] (Float) pin->(Top pin) of [{Sub Node 2}] and (Top pin) of [{Sub Node 3}]->[Select] node with (False) pin in from [{Sub Node 2}], (True) pin in from [{Sub Node 3}], and (Index) pin in from {“Negation”} input parameter->(Return Value) pin from [Select] node connected to the (Value) pin of a [Clamp (Float)] node (leave the (Min) pin as 0.0 and set the (Max) pin as the variable for whatever the maximum health is for your character->(Return Value) pin from the [Clamp (Float)] node to the incoming (Float) pin on the [Set {Health}] node

{Sub Node 2}: [Float + Float} node with the (Float) pin from the [Get {Health}] node connected to the (Top pin) and the [Make Literal Float] node’s (Float) pin connected to the (Bottom pin)->(Return Value pin) from the [Float - Float] node connected to the (False) pin on the [Select] node

The last node is very similar, just pay attention that it’s a [Float - Foat] node and it connects to the (True) pin on the [Select] node.

{Sub Node 3}: [Float - Float} node with the (Float) pin from the [Get {Health}] node connected to the (Top pin) and the [Make Literal Float] node’s (Float) pin connected to the (Bottom pin)->(Return Value pin) from the [Float - Float] node connected to the (True) pin on the [Select] node

It’s important that your [Float - Float] pins are correct because negation laws are not commutative.

That’s the logic behind how that can be cleaned up, unless I’m mistaking its intended purpose. I’ve used words instead of pictures to explain the logic without giving the answer.

Anyway, let me know how it goes.

Hey Zakku. Thanks for getting back to me! I’m calling each function with a “OnClicked” event - 5 different buttons for each image.

For the Enumerator - what type of Enum am I creating and how do I set my textures to it? Hopefully I can figure it out from there.

Thanks!

In your [Content Browser], just right-click and choose [Enumerator], which is in the [Blueprint] sub-menu.

[Enumerators] are basically numbers assigned to a description so that you can refer to an option without getting mixed up with “Option1”, “*2”, “*3”, etc. So, for every option you have under the (Texture) pin, you can create a [Numerator] out of this list and use it as a means to communicate with your function, choosing whichever option you would like to use whenever you call it. This will cut down on redundancy and having to manually assign the texture to the nodes within the function.

Also, I see now that you’re calling this within the [Event Graph] of your player. If you’re making a multiplayer game, it’s a bit dangerous to allow the players’ blueprints to change their health.