I’m new to the Unreal Engine but not to the C++, Visual Studio etc. (have actually more than 30 years programming experience)
I 'm currently working on a new custom blueprint. I’ve added a custom property, and custom getter and setter functions. It works as expected. I’ve also added a simple validation to my setter, which prevents wrong values to be set to my property.
Is it a recommended way to validate things?
void UCustomBP::SetWidth(int32 value)
{
if (value <= 0)
{
UE_LOG(LogTemp, Warning, TEXT("The Width must be larger than zero."));
return;
}
if (Width == value)
return;
Width = value;
....
}
What is the recommended way to notify the user in the Blueprint Editor in case a wrong value was set to a property? Preferably I would show an error in the blueprint box itself, like all other blueprints do.
How to do this in C++?
I’ve already searched everwhere, but haven’t found any answer.
There is literally no detailed documentation for such basic topics.
If I understand correctly, what you want to do is to highlight in red or something like that the input of a BP node if the value is not valid? Or just show it during runtime?
As far as I know, that’s not possible. You would have to make some engine modifications or some complex blueprint editor plugin.
Keep in mind that you can’t predict what a value will be during runtime. If you set a variable as input which is initialized at 0 but is modified while playing, the node wouldn’t allow you, or you would have an annoying message constantly on the node.
You can use some modifiers like “DeprecatedFunction” or “FunctionWithComment”, but those are permanent, not based on internal checks. Also the function would have to be marked as “BlueprintInternalUseOnly”.
Maybe if you check how the engine code handles when an input is not valid (you have a variable conneted to an input that you removed from the function, so it’s no longer usable) or how it handles invalid pointers, like “None” actor references and stuff like that and try to replicate it or modify the engine.