How to preview material thumbnail in menu?

Hi I’m now working on a plugins which needs to add a custom sub menu show some materials. For now I can only show the name of these materials in the menu, is it possible to show the material thumbnail just like the detail panel?

What I want to achieve is something like this:

OK I managed to show the material thumbnail in the menu. It might look ugly but it does show the preview. I might need more tweaks to make it look better.

	ThumbnailPool = MakeShareable(
		new FAssetThumbnailPool(
			25,
			false
		)
	);

// then
        UMaterialInterface *Interface = ...;
	UObject* AssetData = Cast<UObject>(Interface);

	TSharedPtr<FAssetThumbnail> Thumbnail =
		MakeShareable(new FAssetThumbnail(AssetData, 128, 128, ThumbnailPool));
	FAssetThumbnailConfig ThumbnailConfig;

	FAssetToolsModule& AssetToolsModule =
		FModuleManager::LoadModuleChecked<FAssetToolsModule>(TEXT("AssetTools"));
	auto RNTypeAssetActions =
		AssetToolsModule.Get().GetAssetTypeActionsForClass(UMaterialInstance::StaticClass());
	ThumbnailConfig.AssetTypeColorOverride = RNTypeAssetActions.Pin()->GetTypeColor();

	return Thumbnail->MakeThumbnailWidget(ThumbnailConfig);

GREAT! I need the same thing as you, good luck!

Someone said can use this, I just don’t know what to build the c++

UTexture2D* UMyButton::GetTexture2D(UObject* MeshObject)
{
//UAssetManager& AssetManager = UAssetManager::Get();
//FAssetData MeshObjectAssetData;
//AssetManager.GetAssetDataForPath(MeshObject->GetPathName(), MeshObjectAssetData);

//UAssetManager& AssetManager = UAssetManager::Get();
//FAssetData MeshObjectAssetData;
//AssetManager.GetAssetDataForPath(MeshObject->GetPathName(), MeshObjectAssetData);
//UTexture2D* MyTexture2D = Cast<UTexture2D>(MeshObjectAssetData.GetAsset());

int32 _imageRes = 128;
FObjectThumbnail _objectThumnail;
ThumbnailTools::RenderThumbnail(MeshObject, _imageRes, _imageRes, ThumbnailTools::EThumbnailTextureFlushMode::AlwaysFlush, NULL, &_objectThumnail);
TArray<uint8> _myData = _objectThumnail.GetUncompressedImageData();

TArray<FColor> _imageRawColor;
for (int i = 0; i < _myData.Num(); i += 4)
{
	_imageRawColor.Add(FColor(_myData[i + 2], _myData[i + 1], _myData[i], _myData[i + 3]));
}
//FString _fileName = OutputPath.ToString() + "/" + obj->GetName() + FString(".jpg");
IImageWrapperModule& ImageWrapperModule = FModuleManager::LoadModuleChecked<IImageWrapperModule>(FName("ImageWrapper"));
TSharedPtr<IImageWrapper> ImageWrapper = ImageWrapperModule.CreateImageWrapper(EImageFormat::JPEG);
ImageWrapper->SetRaw(_imageRawColor.GetData(), _imageRawColor.GetAllocatedSize(), _imageRes, _imageRes, ERGBFormat::BGRA, 8);
const TArray<uint8>& _ImageData = ImageWrapper->GetCompressed(100);
UTexture2D*  MyTexture2D = UKismetRenderingLibrary::ImportBufferAsTexture2D(GetWorld(), _ImageData);
return MyTexture2D;

}