Show/Hide UProperty of component depending on other components

Hello together,

I have an actor in my scene with a custom scene component, let’s call it EffectComponent. This EffectComponent has different properties that I want to show or hide based on if the actor has a specifiv other component. E.G. If the actor has a FireComponent, I want to enable UProperties on the EffectComponent without having the game running. Is this in any way possible? Thank you!

If i got your question right, the thing you looking for is the EditCondition metaproperty of uproperty

I can’t provide much info about it, but here is usage example from my project:
UPROPERTY(EditAnywhere, meta = (EditCondition = "InitMode == EMyEnum::EnumValue", EditConditionHides))

Where

  • InitMode is a enum member field defined in the same class as a member covered by this uproperty;
  • Afaik, in EditCondition you may put any valid boolean expression. I’m not sure what extents of its power, but probably you will be able to put something like “if my owner has a component of type i need” here;
  • Just the EditCondition will disable field editability, EditConditionHides will hide it completely.

Thank you for your reply!

actually the EditCondition was my first attempt. I tried to do something like this:

meta = (EditCondition = "IsValid(GetOwner()->GetComponentByClass(UFireComponent::StaticClass()))")

but it didn’t work out. At the moment I have a boolean that can be toggled and shows/hides the associated properties, but I find it strange to have this boolean eventhough the actor might not have the corresponding component.

Sooo, I finally figured it out. I started to look a little bit deeper into the Details Panel Customization (Details Panel Customization | Unreal Engine 4.27 Documentation) and used the IDetailLayoutBuilder:

void FEffectComponentDetails::CustomizeDetails(IDetailLayoutBuilder& DetailBuilder)
{
	TArray<TWeakObjectPtr<UObject>> CustomizedObjs;
	DetailBuilder.GetObjectsBeingCustomized(CustomizedObjs);
	
	bool bHasFireComponent = false;
	for (auto Obj : CustomizedObjs)
	{
		AActor* Owner = Cast<UEffectComponent>(Obj.Get())->GetOwner();
		bHasFireComponent |= 
			IsValid(Owner->GetComponentByClass(UFireComponent::StaticClass()));
	}

	if (!bHasFireComponent)
	{
		DetailBuilder.HideProperty(DetailBuilder.GetProperty("FireEffect"));
	}
}

This actually did the trick.