How do I make Images assigned to UI Widgets default to their original size?

To those encountering this problem, add following code somewhere in Image.cpp:

#if WITH_EDITOR
void UImage::PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent)
{

   const FName PropertyName = (PropertyChangedEvent.Property != nullptr) ? PropertyChangedEvent.Property->GetFName() : NAME_None;

   if (PropertyName == FName(TEXT("ResourceObject")))
   {
   	if (UTexture2D* TexResource = Cast<UTexture2D>(Brush.GetResourceObject()))
   	{
   		Brush.ImageSize.X = TexResource->GetSizeX();
   		Brush.ImageSize.Y = TexResource->GetSizeY();
   	}
   }
   Super::PostEditChangeProperty(PropertyChangedEvent);
}
#endif

And Image.h:

#if WITH_EDITOR
	virtual void PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent) override;
#endif

The code is pretty much self-explanatory.

3 Likes

I am also have this issue in 5.3, thank you for solutions.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.