Unreal Blueprint Optimization

Im fairly new to visual scripting and Blueprints. I wanted to try this out but couldn’t find much information on specific topics that I have doubts about.

First iteration
Below is a function from a function library that returns a speed_float based on the speed_type_enum. The enum has three constant types, while the other two are player-specific, so they needed to be global variables stored in the Game Instance.

To access the Game Instance, I had to use a Cast Node every time I needed to retrieve a different speed variable. This was because of the flow of execution pins from the Switch to the Return node.

Second iteration
I thought I could use a local variable to store the Game Instance, but it could only be assigned before the Switch Node. This is problematic since I need the Game Instance only twice out of the five cases.

So, I implemented the following approach:

Im not sure which approach is more efficient. Perhaps I need to rethink the entire speed-type functionality.

For context, the Speed_Type_Enum is stored in the base BP_Character, which is inherited by both BP_Player and BP_Enemy. My initial thought was that it would make the Behavior Tree easier to manage if I used an enum instead of float values to make decisions.

1 Like

The first implementation makes the most sense given the information on hand. Under the first implementation you only have to cast if requesting PlayerWalk or PlayerSprint. Under the second scenario you’re casting regardless of the enum value.

That said, unless you’re calling this function on tick, I wouldn’t be too concerned about the cast and subsequent performance costs. Even then, the impact will likely be well into the noise. Remember, perfect is the enemy of good…

1 Like

If you don’t want to use a cast, you can talk to the GI with an interface…

1 Like