hi,
I’m new to Blueprint…trying to do something very simple in basic programming (i think! my programming skills are pretty bad) but I can’t figure it out in BP
something like where a knob would cycle through the colors…so when the knob input is between 0-340 it would go from black to red, 341-680, black to blue, 680-1024, black to green (or really whatever…this would be a test for other things…just trying to setup the logic)
so first i would have an int that is the knob data, and then i would have some map ranges to map the 0-340 from 0-1, etc to put into the MakeLinearColor node. then something like:
int x; //(knob value to trigger the if conditionals)
float y; //(knob value mapped from 0-1 to apply to the MakeLinearColor;
float red;
float blue;
float green;
if(x<=340){
red=y;
blue=0;
green=0;
}
if (x<=640&&x>=340){
red=0;
blue=y;
green=0;
}
if (x>=640&&x<=1024){
red=0;
blue=0;
green=y;
}
so far i’ve been using a multigate to activate a bunch of compare floats and set vector param value all at once. attached is an image i think.
I feel like there are some basic things about blueprint i’m not getting. it’s cycling through the colors but red and blue are mixed together…and other weird jitters that i just don’t understand.
any help is much appreciated!!
thanks for the response. i’m not sure exactly how i would set up an in between trigger with branches…i.e. how to say if the number is greater than 300 AND less than 600, do this. doing a compareFloat seemed easier and i think it’s a similar thing…but i’m probably not understanding something?
You have your value, check if the value is in range, and use branches to change the color accordingly. I made a sphere that will change color based on a value that increases every tick, this should work for you:
Technically you don’t even need to use In range. Should work with just a “less than” or < operator going into the branch.
ie:
if x < 100 use color A
if x < 200 use color B
if x < 300 use color C
if you do the checks in order there is no need to waste extra calculations making sure its also not under that settings threshold since it would be caught be the previous if.
ie, a value of 50 will only return color A since it will return True and not hit the second branch which should only be hooked up to “False”. So it returns true on the first check and is done.
if the value was 150, it returns false on the first branch, then true. Simple.
Sure, the performance impact is negligible, and this is about a trivial example as it gets
But regardless, less variables/code means less chance for bugs.
For example, in the first example - if someone changes the Max value for the first node from 100 to 90, but missed seeing that they also need to update the minimum value on the second node, theres now a potential bug when the value is between 90 and 100 - nothing would fire - which might (?) not be expected, and tricky to find!
Its a lot like having a if else statement versus a if in programming. If the previous statement is found, ignore all the rest (if) however, if the previous statement is found to be true, check all the others just in case they are true as well, (else if).
Ironically it can get a lot more technical than that, and depending on the situation the preference changes. For this color choosing algorithm, if I were to accomplish this in programming Id do something along the lines of a while loop, followed by the values in if else statements.
While the loop parameter is true, it will continuously check whats inside the loop, ie our else if statements, and it will do those. basically agreeing with the other guys here, just offering my opinion on it.
One more thing though, doing greater than or equal too might be a better option, just remember to put a limiter on the variables and make sure they are encapsulated within their value ranges, otherwise you could escape the given fields and develop a bug like phantasie17 mentioned.
I’d use a timeline for this - Set one up with 3 float curves for R,G,B and stagger them - then lerp from your variable to scale the values between the time range of the timeline and use it to set the time on the timeline. Then you get your R G and B floats - you can customise the ramping of colour values this way.
everyone thank you so much! this was immensely helpful. i learned a lot about setting up logic. in the end i went with what dannington above said so i could get the color ramp. so easy! i didn’t even think to use a timeline to scrub through like that…
here’s a screen shot of what i did…with the >< algorithm saved but not in use…i think i’ll use it for something else.