Hi, what would be the best way to make changes to variables, here is my example. Lets say I need to change a Boolean to True. Should I just set the Boolean to true and that’s it or should I first check if the Boolean is True or false first then change it to True if it is False. I know this is really simple question but how does unreal engine handle this? Is it faster just doing no checks or does it actually take longer somehow with the internal engine code trying to figure it out? I always wondered the same thing about setting all of the other variables. Because it will save me a lot of time if I just make the variable what it should be and not worry about what it was.
I just set it where i need to set it no matter how it is. I think that doing checks would be pretty much the same.
but it all depends on what you are doing, i have an actor that is updated by other actors, and in a certain progress i can set an boolean that this is already update and doesnt need it again right now.
If you are setting a variable to a new value and you don’t need to do anything with the old value, there is no point to checking it. Just set the new value.
Getting a variable is quicker than setting it but you only need to worry about this in rare cases where you are setting ten thousand or more variables every frame. I would choose Readability before Performance in this example.
Games must be able to adapt during development and often only a fraction of it needs this kind of optimization applied to it while the rest needs to be easy to modify.