how to realize large if-else jumble in blueprint?

How can I realize a nasty nested if-else jumble like the one below in blueprint in the most compact way?
update: I need to do the overall thing in a blueprint but I’d prefer a solution that implements the nested if-else in a C++ code that I can use in the blueprint. The problem is I don’t know how to use C++ codes or macros in blueprint.

if (x < val1a) 
 {
            if (y < val2a) 
            { 
                 z = a1
            }
           else if (y < val2b) 
            { 
                 z = a2
            }
            else if (y < val2c) 
            { 
                 z = a3
            }
 }
else if (x < val1b) 
 {
            if (y < val2a) 
            { 
                 z = b1
            }
           else if (y < val2b) 
            { 
                 z = b2
            }
            else if (y < val2c) 
            { 
                 z = b3
            }
 }
else if (x < val1c) 
 {
            if (y < val3a) 
            { 
                 z = c1
            }
           else if (y < val3b) 
            { 
                 z = c2
            }
            else if (y < val3c) 
            { 
                 z = c3
            }
 }

no i meant how to realize it when I wrote “realize”. blueprint visuals would really help. it is not a homework. just something i need to do without it getting out of hand. there is no way to formulize this. all need to be realized in the same function/blueprint. x is camera distance and y is gaze distance. the actual if-else thing is much larger so i need a smart solution that is compact. not sure if your intent was pure trolling but thanks anyway

there is no if-else system implemented in blueprints.
what you can do is:
pavk the whole branch-in-branch-in-branch…etc thing into a macro, that has multiple return execs
that macro is much smaller (compacter) in the actual graphs, but bigger when editing it

i think a select node would do the trick wouldnt it

Looks like a perfect case for nested C++ switches:

Oh forgot…
You’ll also need “less thans” in the case:

How about this… …more spaghetti than nested if-else… :stuck_out_tongue_winking_eye:

1 Like

Forgot about the outer if-then-else…

1 Like

Just to be sure… are all the variables correct?
For the x has val1a, val1b, val1c to compare.
But for the y, same (val2a,val2b,val2c) is used for first 2 groups and (val3a,val3b, val3c) is used for the last group.

And I’m curious: what is the application scenario for this if-else logic?

for a homework application i think :face_in_clouds:

Would be helpful to know if he’s looking to do this with existing Blueprint nodes…
Of if he’s looking to do it by creating C++ code within a custom Blueprint function node??
Reading through this thread a few times I’m still not sure which way of these he wants to go…

Compact? Written in C++ and called as a blueprint callable function. Or, tucked into a macro, function or a collapsed graph.

But just on a single graph? A bunch of select nodes, which either return the value if the condition is met, or return the value given by another select node which does the same, until you are at the final condition within the bracket at which you will either return the result given by the last condition, or if that fails, z.

Just to be sure… are all the variables correct?
For the x has val1a, val1b, val1c to compare.
But for the y, same (val2a,val2b,val2c) is used for first 2 groups and (val3a,val3b, val3c) is used for the last group.

yes unfortunately they are different for different thresholds of x

And I’m curious: what is the application scenario for this if-else logic?

I need to place different versions of the same mesh according to its distance from camera and gaze location. Actually that is another challenge I need to find a solution :confused:

Would be helpful to know if he’s looking to do this with existing Blueprint nodes…
Of if he’s looking to do it by creating C++ code within a custom Blueprint function node??
Reading through this thread a few times I’m still not sure which way of these he wants to go…

I need to use a blueprint but I wouldn’t mind realizing this nested if-else with a C++ code that I can use in the blueprint. The problem is I’ve never done this so I’d appreciate a solution like that or at least pointers to resources telling how to do that

Forgot about the outer if-then-else…

Thank you very much! I’ll resort to these if I can’t find a better way

for a homework application i think :face_in_clouds:

Oh god for the 2nd time, no this is not a homework. Is every question here interrogated whether it is homework now? Why bother with questions then? No this is actually part of my research. So a neat solution would not be helping something unethical but on the contrary it’d be helping scientific research

This is the more compact i get only with blueprints
Create a macro


Organize nodes

2 Likes

This is definitely the right approach.

You can create a Blueprint function library in C++ and mark the function as BlueprintCallable:

Create a c++ Class

.h file
#pragma once

#include "CoreMinimal.h"
#include "Kismet/BlueprintFunctionLibrary.h"
#include "MyBlueprintFunctionLibrary.generated.h"

/**
 *
 */
UCLASS()
class ASSETUTILITYCOURSE_API UMyBlueprintFunctionLibrary : public UBlueprintFunctionLibrary
{
	GENERATED_BODY()

	UFUNCTION(BlueprintCallable, Category="Helpers")
	static void DoStuff(int32 x, int32 y, int32 a1, int32 a2, int32 a3, int32 b1, int32 b2, int32 b3, int32 c1, int32 c2, int32 c3, int32 val1a, int32 val2a, int32 val3a, int32 val1b, int32 val2b, int32 val3b, int32 val1c, int32 val2c, int32 val3c, int32& z)
	{
		{
			if (x < val1a)
			{
				if (y < val2a)
				{
					z = a1;
				}
				else if (y < val2b)
				{
					z = a2;
				}
				else if (y < val2c)
				{
					z = a3;
				}
			}
			else if (x < val1b)
			{
				if (y < val2a)
				{
					z = b1;
				}
				else if (y < val2b)
				{
					z = b2;
				}
				else if (y < val2c)
				{
					z = b3;
				}
			}
			else if (x < val1c)
			{
				if (y < val3a)
				{
					z = c1;
				}
				else if (y < val3b)
				{
					z = c2;
				}
				else if (y < val3c)
				{
					z = c3;
				}
			}
		}
	}
};

Result:

I don’t know what you are doing but it looks pretty nasty :sweat_smile:

2 Likes

What are you referring to?
To be honest the store was faster than ever for me this week, that’s why I’m asking!

Awesome! Are you an angel? :star_struck:
What if a1, a2… are instanced static meshes? How should I modify the input and output types?