Let’s say we’re creating an actor with a mesh component that’s attached to a root scene component. We’ll expose three float variables that allow the location and scale of the mesh to be adjusted relative to the root: DistanceFromView, LengthScale, and RadialScale:
In the Construction Script, we want to set the relative location and scale of the mesh component based on these values. The work needed to accomplish that is trivial, but there’s a right way and a wrong way to do it, even with the exact same nodes.
Let’s look at the wrong way:
http://awforsythe.com/i/bpstyle_reticle_graph_bad_t.jpg
We’re doing what was asked for, but it’s hard to see what’s going on. Look how much space we’re using for two function calls. Look how far our eye has to travel to figure out what arguments are being passed in. Notice how everything is encased in a comment block that doesn’t give us any new information: we can tell very easily from the two function calls that we’re setting the location and scale, thank you very much.
If you were implementing the same actor in C++, you surely wouldn’t write code like this:
Any programmer worth their salt will tell you that this code is horrible! Inexcusable! Ugly as sin! It produces the result we asked for, but that’s not the only thing it needs to do. It also needs to be readable and maintainable. Another programmer should be able to come along and understand what this code does at a glance.
Here’s how this simple example would look, in C++, with good style:
And here’s how it should look in Blueprints:
We can see the execution flow, straight across. We can see that there are two function calls, and we can see the arguments that are being passed to each function. There’s no guesswork. We’ve gone from a haphazard arrangement to one that reflects the intention and behavior of our code. Just like proper use of whitespace in C++ makes code easier to read and helps us group related statements, proper use of the 2D space given to us in a Blueprint gives us the same benefits.
So please, pay attention to style when creating Blueprints. Keep things orderly and organized and readable. You’ll end up producing better code for it.