Intro #
UPROPERTIES in Unreal Engine have a bunch of useful Meta-data Specifiers which can be applied to add additional validation and functionality. This blog post explains how to use the EditCondition (and EditConditionHides) specifiers to selectively show, disable or hide properties in the editor, based upon the value of another UPROPERTY. Shout-out to Jack Magnay for the "Advanced Usage" snippet.
GitHub Gist: https://git.io/JJ3QC
Basic Usage #
This example below disables the MyNumber property when MyFlag is false.
UPROPERTY(EditAnywhere, Category="Demo")bool MyFlag = true;UPROPERTY(EditAnywhere, Category="Demo", meta=(EditCondition="MyFlag"))int MyNumber = 0;
Basic Usage (Inverted) #
This example below is similar to the first, but disables the MyNumber property when MyFlag is true.
UPROPERTY(EditAnywhere, Category="Demo")bool MyFlag = true;UPROPERTY(EditAnywhere, Category="Demo", meta=(EditCondition="!MyFlag"))int MyNumber = 0;
Basic Usage (Hiding) #
This example below is similar to the first, but fully hides the MyNumber property when MyFlag is true by adding the EditConditionHides specifier.
UPROPERTY(EditAnywhere, Category="Demo")bool MyFlag = true;UPROPERTY(EditAnywhere, Category="Demo", meta=(EditCondition="MyFlag", EditConditionHides))int MyNumber = 0;
Advanced Usage (Enum) #
As of UE4 4.23 (see release notes) "The EditCondition meta tag is no longer limited to a single boolean property. It is now evaluated using a full-fledged expression parser, meaning you can include a full C++ expression." - This means we can do things like disabling a properties based on the value of an enum UPROPERTY, as shown below.
//------------------------------------------------------------------------------------------------------------------------------UENUM(BlueprintType)enum class EMovementConfig : uint8{ ConstantSpeed, Increment};//------------------------------------------------------------------------------------------------------------------------------UPROPERTY(EditAnywhere, Category="Demo")EMovementConfig MovementConfig = EMovementConfig::ConstantSpeed;UPROPERTY(EditAnywhere, Category="Demo", meta=(EditCondition="MovementConfig == EMovementConfig::ConstantSpeed"))float Speed = 10.0f;UPROPERTY(EditAnywhere, Category = "Demo", meta = (EditCondition="MovementConfig == EMovementConfig::Increment"))float Increment = 1.0f;//------------------------------------------------------------------------------------------------------------------------------