Ares9323
(Ares9323)
August 29, 2025, 5:46pm
1
Continuing the discussion from Hex code to RGB :
Ask chat GPT to make whole function for yoursaelf.
Copy paste code from chat to CPP
And compile.
Even for me (I know CPP) this is really fast way to make those small C++ functions.
Usually at worst it is matter of fixing singe bug in what chat made. But then you do not have those 20-30 weird functions that do very simple things, instead you have single (or two) files in C++ with single class.
Example of this (I did not check this function for bugs, chat does them often, so be sure to check it):
my prompt:
Create function for unreal 5, that converts Text variable (containing hex values of color RGBA) into unreal linear color. Expose Color as text and resulting linear color to blueprints. Make this function Pure. IT should have linear color input variable that represents “error color” and if translation of input text cannot be done to linear color, set result as that error color. This should be C++ function.
Chat first result:
“ColorConversionLibrary.h:”
#pragma once
#include "Kismet/BlueprintFunctionLibrary.h"
#include "ColorConversionLibrary.generated.h"
UCLASS()
class YOURPROJECT_API UColorConversionLibrary : public UBlueprintFunctionLibrary
{
GENERATED_BODY()
public:
UFUNCTION(BlueprintPure, Category = "Color Conversion")
static FLinearColor HexToLinearColor(const FText& ColorText, const FLinearColor& ErrorColor);
};
“ColorConversionLibrary.cpp:”
#include "ColorConversionLibrary.h"
FLinearColor UColorConversionLibrary::HexToLinearColor(const FText& ColorText, const FLinearColor& ErrorColor)
{
FString ColorString = ColorText.ToString();
FLinearColor Result;
if (ColorString.StartsWith("#"))
{
ColorString.RemoveAt(0); // Remove the '#' character
// Convert the remaining string to FColor
FColor ParsedColor;
if (ParsedColor.InitFromString(ColorString))
{
Result = ParsedColor;
}
else
{
Result = ErrorColor;
}
}
else
{
Result = ErrorColor;
}
return Result;
}
And bonus is you will get used to C++. With second bonus: all code in blueprints gets much more maintainable.
You probably have just copied code from ChatGPT and haven’t even looked at the definition of InitFromString before posting it…
Ares9323
(Ares9323)
August 29, 2025, 5:46pm
2
The correct approach to get a FLinearColor from a FString is using the existing function that converts FString to FColor and then FColor to FLinearColor:
FLinearColor HexToLinearColor(const FString& HexString)
{
// Use existing FromHex
const FColor Color = FColor::FromHex(HexString);
// Convert to linear color (0–1 range)
return FLinearColor(Color);
}