UE4

UE4 Customized Property Layout 갱신

TigerFish 2022. 4. 8. 21:09

글을 쓰는 목적

 

UDataTable 저장 후 Property Layout 갱신이 필요한 상황인데 저장 이벤트를 기억하기 위해 글을 씀


작업 환경

 

UE4.26


 

Customized Property Layout 갱신 방법

 

UDataTable을 저장하면 최종 OnObjectSaved 이벤트를 호출한다. 

FCoreUObjectDelegates::OnObjectSaved.Broadcast(this);

 

OnObjectSaved 호출을 받아 갱신하면 되는데 여기서 중요한 것은 Custom Property Layout을 만들 때 CustomizeChildren을 호출 받을 때 PropertyUtilities 포인터를 저장한다.

그리고  OnObjectSaved가 호출될때 PropertyUtiltites의 ForeceRefresh로 갱신하여 Layout을 갱신한다. 

 

FTestPropertTypeCustomization::FTestPropertTypeCustomization()
{
	ObjectSavedHandle = FCoreUObjectDelegates::OnObjectSaved.AddRaw(this
	, &FPersProjTableSelectorDetailPanel::OnInvalidProperty);
}

FTestPropertTypeCustomization::~FTestPropertTypeCustomization()
{
	FCoreUObjectDelegates::OnObjectSaved.Remove(ObjectSavedHandle);
}

void FTestPropertTypeCustomization::CustomizeChildren(TSharedRef<IPropertyHandle> inPropertyHandle, IDetailChildrenBuilder& inChildBuilder, IPropertyTypeCustomizationUtils& inCustomizationUtils)
{	
	PropertyUtilities = inCustomizationUtils.GetPropertyUtilities();
}

void FTestPropertTypeCustomization::OnInvalidProperty(UObject* inPackage)
{
	if (nullptr == inPackage)
	{
		return;
	}

	UDataTable* table = Cast<UDataTable>(inPackage);
	if (nullptr == table)
	{
		return;
	}

	PropertyUtilities->ForceRefresh();
}

참고

 

https://forums.unrealengine.com/t/how-to-force-ipropertytypecustomization-to-redraw/361579/7

 

How to force IPropertyTypeCustomization to redraw

Hi kamrann, as I debugged through all the ue4 code, I finally realized that customizeHeader and customizeChildren are only getting called on initialization anyway. So there can’t exist a way for a simple IPropertyCustomization to get these functions call

forums.unrealengine.com