Multiple events on variable Ranges ?

Hey guys !
I have a problem with a power reserve system im trying to make.

I have an Int Variable “Power Reserve” that is going from 0 to 999.

-i have different electrical devices that drain power from the “Power Reserve”
-i also have a way to recharge the “Power Reserve”

Now my goal is the following, i want to check the “Power Reserve” Variable, and if its current value is between a set of ranges, trigger multiple Events.

Example :
Power : 0 = “Event Empty”
Power : 1-250 = “Event Power Low”
Power : 250-500 = “Event Power Medium”
Power : 500-999 = “Event Power OK”

The only way i figured how to do it is with a set of Branches, but its seems stupid…

this is the current working system i have :

Is there a better way to achieve this ?

Somthing like a map with ranges or an array of some kind that would convert a range into an index ?

1 Like

In this very case, it could be just:

But you may have other cases in mind, too. Do you?


but its seems stupid…

But it works!

2 Likes

(post deleted by author)

It work well in my case, thanks you !

But just to know, what could i do if i need ranges that would be more specific like :
1-15
16-250
250-450
and so on, would there be a good ption for that situation ?

1 Like

How about we describe it with a curve:

And then sample it:

You could make it fancy by adding an enumerator, something like this should :crossed_fingers: work:

Round to int and use int in the Map to be safe, just in case. But could be fine as is.

2 Likes

Okay very interesting way of doing it ! i will try that when i will need it on a future case.

do you think my original solution with the branches was more heavy on the cpu compared to your first answer ?

Probably, maybe. I don’t know. :melting_face:

  • can we measure it? No.
  • will anyone ever notice? No, only you and your team.
  • is it worth focusing on? No.
  • does it matter here? Also NO, but with caps lock.

What matters more is making the script easy to read and find (for you and others).


From what I understand about Blueprints - the cost is somewhat linear - the more nodes to step through, the more computationally expensive things get. But it’s not really measurable in this case. You’d need to do it a thousand times per second, and even then the cost of the BP loop itself would be higher than that of calling some C++ functionality via a node.

  • adopt Event Driven approach
  • avoid unnecessary hard references
  • avoid 4k textures on tiny props
  • avoid looooong BP loops, especially on Tick
  • don’t Tick things that do not need to be updated every frame
1 Like

Again, thanks a lot for your help !

1 Like