I found in a case thumbnails of custom types could look differently in the Content Browser from in the Details Panels if I drew a texture not filling the whole canvas.
So I created a simple asset type to test the case. It has a thumbnail renderer to draw a given texture on the canvas with given padding.
In the following picture, you can see when the given texture is drawn with a padding of 10 pixels, the thumbnail in the Content Browser looks fine but it’s not true in the Details Panel.
If I try to increase the padding, the space surrounding the given texture will expand further like the following picture with 20 pixel padding.
Hence, I think it is a bug and hope someone can fix it because I am doing something like that in my plug-in.
If someone wants to reproduce the bug, they can use the following code:
My test asset type:
UCLASS(BlueprintType, Blueprintable)
class TESTTHUMBNAIL_API UMyAsset : public UObject
{
GENERATED_BODY()
public:
UPROPERTY(EditAnywhere)
class UMyAsset* TestAsset;
/* Specifies the background texture of the thumbnail. */
UPROPERTY(EditAnywhere, Category = "Thumbnail")
class UTexture2D* ThumbnailTexture;
UPROPERTY(EditAnywhere, Category = "Thumbnail", Meta = (ClampMin = 0, UIMin = 0))
FMargin ThumbnailPadding;
};
A Thumbnail renderer for the asset type:
UCLASS()
class TESTTHUMBNAILEDITOR_API UMyAssetThumbnailRenderer : public UThumbnailRenderer
{
GENERATED_BODY()
// UThumbnailRenderer interface
virtual void Draw(UObject* Object, int32 X, int32 Y, uint32 Width, uint32 Height, FRenderTarget*, FCanvas* Canvas) override;
// End of UThumbnailRenderer interface
};
void UMyAssetThumbnailRenderer::Draw(UObject* Object, int32 X, int32 Y, uint32 Width, uint32 Height, FRenderTarget*, FCanvas* Canvas)
{
UMyAsset* Asset = Cast<UMyAsset>(Object);
if (Asset == nullptr || Asset->ThumbnailTexture == nullptr ) { return; }
Canvas->DrawTile(
(float)X + Asset->ThumbnailPadding.Left,
(float)Y + Asset->ThumbnailPadding.Top,
(float)Width - Asset->ThumbnailPadding.Left - Asset->ThumbnailPadding.Right,
(float)Height - Asset->ThumbnailPadding.Top - Asset->ThumbnailPadding.Bottom,
0.0f,
0.0f,
1.0f,
1.0f,
FLinearColor::White,
Asset->ThumbnailTexture->Resource,
true);
}