Check if variable is set or just set it?

Hi I’m sorry if this have been asked but i couldn’t find it.

Is there any performance gain to check if a variable is set or not before setting it.

Does it “cost” less, more or equal to check first or is it better to just set it over and over?

In this particular blueprint I don’t have to worry about this since its only triggered once per pickup but I wanted to give a visible example.

Lets say that function droped is triggered every second for the sake of argument.

Well, not checking first means fewer operations are carried out, so it’s technically less “costly” in this case to just set it right away.

In the grand scheme of things however, you’d probably have to do this thousands of times per frame to see any measurable difference.

In general, I’ll conditionalize a block of code (gates are awesome for this) only if it’s running a Tick and there’s expensive stuff going on that only needs to happen occasionally. The performance gain/loss in your two cases is negligible.

Thanks for the answer. I guessed you would answer something like that. I’m a programmer so I understand your points but it’s just I’m a little nervous about performance when it comes to blueprints so I had to ask. I do know c++ so I will do most logic later on in code but blueprints is so good for rapid prototyping.

Thanks again. I will check out gate. Haven’t used those yet.

A gate is just like a flood gate might sound, you plug your water into the ‘Enter’, and then you can open and close the gate whenever you want, but water will only flow if there is water going to the gate, hopefully that makes sense.

Ok. Seems simple enough. Thanks.


Here’s a gate in action, part of my script to move a turn-based unit from one tile to another. You can just fire off events into them and it reduces the amount of execute lines sweeping across the screen. Also fantastic for button press/release events.

Ok. Seems convenient. I can see how this can be useful.

Thanks for all your explanation. Great forum this is. :smiley: