Convert color format 128,23,240

Hi, I need some help converting a DataTable I imported into something I can use in a Blueprint for colors. I initially chose the color format as a string (number, number, number) since I wasn’t sure about the best format. Now, I’m looking for a way to convert it in the Blueprint.

I’m open to any solution that works, whether it involves changing the DataTable variable type or anything in the Blueprint that converts from a string like 128,23,240 to something like Linear Color or RGB color.

Thank you.
Sergio

You make it much more simpler, just create a struct with Color datatype, and then make a datatable for it. That you won’t have to convert the string to a color or anything like that.

And the data table

Then in blueprints you can access the desired one using this sort of logic

@shadymorningstar Thanks for the help.

Making it a bit tricky is that I’m importing the table from Excel/Google Sheets, and I have colors represented like this. In the struct file where I define the format, I use RGB as a string because I’m not sure about a color format that matches. Now, inside the Blueprint, I need to convert a string like 239,150,0 to a format Unreal can read.

I end up having the RGB in my BP like this(see image please)
Screenshot 2023-11-15 155134

image

After getting the RGB Value, you can then assign it to a variable, then use the following logic to separate the R, G and B values, then make a color using those values. ParseIntoArray function takes your input string which is RGB in your case, then we break it using the delimiter " , " in this case. So it creates an array of the separated values, which we can then access by indices.

1 Like

@shadymorningstar

You are too kind, thank you for the help, I’m really excited to solve this and finally get my BP working :slight_smile:

The code is more efficient than mine, but we’re getting the same result. When I follow your suggestion, I get this result: (R=239.000000, G=150.000000, B=0.000000, A=1.000000). When I plug this into my material color (using a Linear Color structure), it works, but the colors look a bit strange.

I’m thinking they should probably be between 0 and 1, but I could be mistaken.

1 Like

You can try it with the simple Color structure rather than a LinearColor one. The results slightly vary due to how these color schemes are processed. Also try fiddling with other material properties such as specular, metallic, roughness etc. to see if you can achieve the look you want.

Thank you @shadymorningstar

I think I fixed it by switching to RGBE (linear color). Saw some weird number in the alpha, so I broke down the color. It looks like the alpha of 136 comes from the RGBE conversion. Not sure why it’s 136, but I just set it to 0 to sort it out.

1 Like