Download

Alternative for Branch?

Hey, I am looking for a cleaner way to managing my ever growing tree of branching executions. Is there a function or method I can use to replace the branches with something more elegant? Part of the problem is the messiness of having this many branches and the other part is obviously trying to keep it all straight in my head as to how it is supposed to flow.

don’t know if you know this but you can have separate trees inside of functions, then just replace that segment in the original bit with the function, helps keep things tidy. just saw that you know how to use functions so disregard this post, I know of no other way to keep it tidy, to be honest blueprint is great but its almost easier just to write the code, half the time I can’t make the jump from what I know should work in a code way to what would work in blueprint, plus as you say its hard to keep things organised, you can use comments to contain bits of code, at least that way you should be able to get the jist of what you were doing

If you’re trying to manage states (mutually exclusive) then you can make an enum and use a “switch on enum”.

It will have an output for each of your states! This way you can have like 5 outputs on one switch instead of having 5 separate bool checks.

Another option is if a number of bool checks result in the same outcome, you can use an OR (or NOT or XOR) node to group multiple bool checks into the same branch. I’m sure there are some more tips I’m forgetting!

Nick

I am not sure I want to hide any code away behind a function as I am still learning and that would be a quick way to forget where I put something. :stuck_out_tongue: As I finalize things and become more confident in the flow I may well do that. Using comments and lots of variables has helped quite a bit, but I have as many as 9 branches leading to some outcomes and I am just getting started. I am hoping for a better layout before it gets too out of hand. :stuck_out_tongue:

I hear a lot of people who can code prefer to think in terms of code, but for me as a non-programmer this visual system is a godsend. I have made more progress in 20 hours of trial by error than what took me weeks and months in other scripting languages. :slight_smile:

This sounds intriguing. I don’t really anything about Enums. I don’t see a “switch on enum” in any of the dropdowns or through search, does it come by another name or is a combination of functions?

I will have to hit the documentation on enums and bools tomorrow. Thanks!

You need to create an enum first in the content browser -> New -> Misc -> Enumeration. Within that you then add your enum entries. And then if you search for the name you’ve given your enum it will appear as a Switch in BP.

Ok, so I have an Enum Switch in my blueprint and the output makes sense. The byte input is foreign territory though. Searching for “byte” doesn’t give anything comprehensive as to how they are handled.

The fact that a byte is used to make the switch make sense, though I don’t know if that means outputs are limited to 8 or how it works past 8.

The biggest conceptual issue I have is how I connect my “InRange(Float)” boxes to the byte input. It outputs a bool which tells me whether it is about to add a mesh in a certain area. How do I get half a dozen bools to file neatly into a byte for the enum?

Is there a better chain leading up to the Enum for this situation, or is there a good way to convert my bools to the byte?

An enum is an “enumerated type”. Basically, it’s just a way to have a list of values that are named. For example, you could enumerate parts of the day as Morning, Afternoon, Evening, Night. Then when you hook that up, the switch will clearly label each of its outputs for each day phase.

A byte actually allows 256 different values, not just 8. (2^8)

If you have to check ranges a lot, I’m not quite sure that a switch of this type is really what you want… Depending on exactly what you are doing, I might be able to suggest an alternative. You might want to post your blueprint to get suggestions.

Lastly, I can’t emphasize enough how much it helps to use functions and macros to reduce complexity. Of course I can’t tell if it would help your case without knowing more, but grouping functionality into smaller, understandable bits rather than having everything visible at once is critical. Programmers do that so we can understand what code is doing, not because we understand it. :p. No one can understand an entire complex program at once. :slight_smile:

The more you use blueprints, the more you’ll learn how to solve situations like this elegantly, especially with the help of the community here! The same is true for learning programming generally. Good luck!

This ^
It’s the only way to maintain sanity after your blueprint becomes too complex :wink:

Yes, functions from custom events and macros make life infinitely easier. I discovered them yesterday and they turn a mess of a blueprint into something nice and readable.

I can see how to reference the list randomly, but what is the best way to reference it specifically? Some process where I have say 10 options and each one generates an integer 1-10 that gets fed into the enum?

And I am doing a fair bit of range checking as it generates the map. It checks range then feeds the boolean to the branches. As you can see below I have a real rats nest growing in there…

The enum does help combine some branches on the final random check:

Yeah I definitely plan on using functions as I lock in certain blocks of functionality. The ability to iterate and improve processes with this visual scripting is amazing.

Here is a picture of the current map generation for reference:

Civilization! :smiley:

Indeed! :slight_smile:

I found the Enumerations too cumbersome for my purposes so I went back to branches. Using Find Range to approximate ratios for better control of tile generation.

Using functions definitely helps with the clutter! I guess I can create my own functions to replace the branches, except of course the function would be filled with branches… :stuck_out_tongue:

Once I have fleshed out my Great Wall of Branches here I will try and boil it down to a handful of functions. :slight_smile:

Hi Zeustiak,

I can’t zoom in to see what exactly is going on, but I can’t help but think there might be a better approach, although it is very neatly laid out :slight_smile:

There’s also switch on integer if you want to do something differently for -10…10 as you mentioned above, and another approach that can come in handy if each one is just picking data is to use an array as a data table.

For example, if you want to pick 20 different tiles based on a random roll, you could make an array of your 20 outcomes and index into it. You can get more complicated by doing things like having two arrays, one of items and another of probabilities (e.g., Tile1,7% Tile2,5%, etc…) and write a function that generates a random number and runs thru the array to pick which one based on your distribution.

Cheers,
Michael Noland

Here is a better image of the branches:

Here is a general order of things:
Vector of tile-to-be-generated determined
Vector used in a Range Find to set Boolean variables relating to latitude and longitude
Branches used with lat/long Boolean variables to choose appropriate Climate and Geology Generation functions
Climate/Geology functions generate an instanced mesh according to ratios set for that climate(90/5/5-ocean/desert/jungle for Tropical(Lat) Ocean(Long))

The interger switch looks a little better than the enum, though the branches are still more suitable I think.

Arrays look interesting. I read through the documentation a couple times, though I don’t quite fully understand how to insert them into my functions yet.

Given that the InRange(Float) outputs a boolean, I would probably need some way to convert that boolean to an int or something else if I want to get around the Branches.