EditCondition not working with full C++ expression

According to this doc:

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.

I have an array

UPROPERTY(EditAnywhere, Instanced, Category = "MyCategory")
TArray<TObjectPtr<UCustomClass>> TestArray = {};

and based on the number of elements in it I want to disable editing on another property:

UPROPERY(EditAnywhere, Category="MyCategory", meta = (EditContidion = "!TestArray.IsEmpty()")
FName NextName = NAME_NONE;

so that if the array has no elements I can edit that FName property but it should be greyed out if there are elements in it.

I’ve also tried:

  • TestArray.IsEmpty() - doesn’t hide it as expected (just for testing purposes)
  • TestArray.Num() == 0- not wotking
  • 1 == 0 - always hides it.
  • also tried assigning TestArray.Num() to a bool variable and using that (inspired by my c# knowledge) and unsurprisingly does not work either (i.e. bool bTest = TestArray.Num(); and meta = (EditContidion = "bTest ")

Obviously it is not working as expected otherwise I wouldn’t ask here, so why is that so? am I misreading the documentation?
I have seen this basic doc but that seems like an overkill for the simple thing I’m trying to achive.

Any suggestion will be welcome.

Was this a recent change? I don’t remember reading this in any of the recent patchnotes.

I’d guess that the typo in EditContidion (instead of EditCondition) is part of the problem. Would be interesting to know if it works after fixing that.

You can also specify custom metadata as well so that’s likely why the typo doesn’t cause an error.

The typo comes from me writing this as I couldn’t copy&paste :confused:

The expression parser isn’t fully compiled C++ code, it’s a unique little custom-made parser that can essentially assemble and run a simple math expression. I think it can only contain UPROPERTYs and basic C++ operators.

Storing the array’s Num() into a dummy UPROPERTY variable and then reading that variable in the EditCondition will work, if you can figure out how to update the dummy variable. On an actor you can use PostEditChangeProperty(…) for this.

You can wrap the dummy variable in #if WITH_EDITORONLY_DATA to keep some of the silliness out of shipping builds.

1 Like

That’s somewhat unfortunate. My hope was that something similar to ReplicatedUsing would be possible now. With ReplicatedUsing you simply specify the UFUNCTION that will be called whenever the variable updates from replication over the network. So here you would simply specify a (editor-only) UFUNCTION that can implement the editcondition.

the expression parser can have fully compiled C++ code now, it’s written as an update note in the docs.

^ This is false.

2 Likes

Very good answer. Thanks a lot!

I would also like to be able to do this. Using Array Length to hide single element variable would be a good way to declutter the space.


USTRUCT(BlueprintType)
struct FMyGameRoomElementGroup
{
    GENERATED_BODY()

    UPROPERTY(BlueprintReadWrite, EditAnywhere)
    FString Name = "";

    UPROPERTY(BlueprintReadWrite, EditAnywhere, meta = (EditCondition = "!Elements.IsEmpty()", EditConditionHides))
    UInstancedStaticMeshComponent* Element;

    UPROPERTY(BlueprintReadWrite, EditAnywhere, meta=(EditCondition="Element == nullptr", EditConditionHides))
    TArray<UInstancedStaticMeshComponent*> Elements;

    operator bool() const
    {
        return Name != "";
    }
};


Also, I would like to point out that while the EditCondition works in the Details window, it would also be good to use it to hide pins in Blueprint.

Is this supported now?