Is it possible to convert a string with hex color value to RGB/vector3 in Blueprint?
I need to read hex color values from a data table and set them to dynamic material instances at runtime.
You can use String to Color, and then you can do with it what you want
C++: UKismetStringLibrary::Conv_StringToColor
Ok, thanks Bojann, will try. But, there is no way without using C++?
There is. Use node StringToColor in blueprints.
Hi @PatMag68 this is probably old but I was looking for the same today. A way to convert HEX (#EF9600) for example into linear color in unreal. I think the bellow solution doesn’t work because it’s not the right format, as you can see in several youtube videos about stringtocolor. If you have any other solution please share. Thanks
Blueprints version:
Use this function to make color variables:
There are TWO make color nodes:
- make color that uses FLOAT which is wrong for us
- and “make color” that is under STRUCT which uses byte YOU must add space in “make color” in search context menu!
Edit:
forget C++ it needs yet another function inside.
Thank you @Nawrot
I’m currently working on my BP and delving into the RGB to Color (HEX will go after) conversion in Unreal (you know, the blue dot thing, I believe it’s linear color). However, I’ve run into a bit of a snag.
I got a tip that if you’re trying to match perceptual values from Photoshop to Unreal, a specific conversion is necessary. Without it, your sRGB values might go through a Linear to sRGB conversion, resulting in pixel complications.
Now, here’s where I could use your expertise: there’s a “Linear to Color RGBE” node, and while it seems decent, the alpha is acting up. I’m not entirely sure if this node is the solution or if there’s a better one.
Would you mind helping me figure out the math behind this? Your help would be highly appreciated.
Thanks
I searched this forum and found similar problem:
And last part of last post:
If this is correct calculation for matching photoshop colors. Cod this as pure function in BP, and multiply RGB color values by result from it.
That power function has 2.4 so that may be usual gamma correction.
However if conversion is not linear you need to find formula or get somebody who can spot color differences (some pro artist).
ps.
I think this formula is accurate, there is post on stackoverflow explaining it with this same formula.
here are two functions to convert sRGB to linear and back:
UFUNCTION(BlueprintPure, Category = "Color Conversion")
static float sRGBToLinear(float Value)
{
if (Value >= 0.04045f)
{
return FMath::Pow((Value + 0.055f) / 1.055f, 2.4f);
}
else
{
return Value / 12.92f;
}
}
and opposite:
UFUNCTION(BlueprintPure, Category = "Color Conversion")
static float LinearToSRGB(float LinearValue)
{
const float Gamma = 2.2f;
return FMath::Clamp(FMath::Pow(LinearValue, 1.0f / Gamma), 0.0f, 1.0f);
}
Those are static so should be placed in C++ blueprint function library. Or just make them in BPs.
Thanks, C++ is out of my skills but I will try to ask for help.
It’s confusing because the advice I got was to convert from srgb to linear in unreal and that I could use some of the existing functions for that.
Thanks
C++ has both formulas right there, just make same calculations in blueprints.
Will try thanks.
Thank you for sharing this! It was driving me crazy until I realized that Make Color input pins are not RGB, but BGR
@MrSchpfmut , this is how I made mine.
Such a great, in depth response and solution. Thank you very much! Using it in my project now to convert .json palettes from Lospec into Unreal-usable format.