Download

Effectively sequencing if statements

I am currently in the process of converting C++ code to blueprints, and am wondering what the most effective way of sequencing if statements would be. Here is my code:


void ABoBaChar::Tick(float DeltaSeconds)
{
	Super::Tick(DeltaSeconds);

	
	


	if (bSprinting)
	{
		if (bSprintMoving)
		{
			StopFire();
		}
	}

	if (bCrouched)
	{

	}

	if (bSliding)
	{
		SlideUpdate(DeltaSeconds);
	}
	else
	{
		if (SlideRefireTime > 0)
		{
			SlideRefireTime -= DeltaSeconds;
		}
		else
		{
			SlideRefireTime = 0;
		}
	}

As you can see, there are quite a few if statements, which could get messy in blueprints. Here is the above code layed out in blueprints:
96b527848cbbecf14db878b05baea158819b877b.png

As you can see, regardless of the first two branches, the if (bSliding) branch will always be reached. Alternatively, I could use a sequence to achieve the following layout in blueprints:
0b3d491b592edd7b28893355406aec47838588ac.png

What I am wondering is if there are any pros/cons to using the 1st/2nd image layouts in blueprints. I personally am accustomed to the messy version (version 1), but would love to use the sequence unless there is some con to using it.

I’d stick to the Sequence node.

Don’t forget about the and node.

In C++, you don’t need sequence nodes, if statements are nested, and code happens sequentially anyways.

They are alot like a block of code, with each output being a line of code. It runs in a single thread from start to finish, so all in one frame, and steps through it’s “Then” statements in order returning at the end.

There is one huge caveat though, if one of the sequence “Then x” statements returns from a function, the remaining “then x” pins will still be evaluated before returning.

For example:

I believe Epic is changing this in either 4.9 or a later release, but make sure you don’t use it as part of a conditional statement that returns, it runs each line no matter what in 4.8.

Yeah, I like to modify the macros so that that ^ doesn’t happen, just like on my Flip Flop I have an exec that swaps the current exec without executing.