Dear Community,
In my newest tutorial I show you how you can make your own custom UMG components that utilize custom render code to make completely new components that you can edit right in the UMG Designer!
**Video**
Here's a video demonstrating my first custom UMG component! Notice how my Slate C++ code works with UMG's render transform system, making animation and render transformations work perfectly!
https://youtube.com/watch?v=1prIYTfng9g
This video is of my [in-game AI editor for Abatron](https://forums.unrealengine.com/showthread.php?45059-Abatron-the-making-of-a-UE4-Hybrid-game-)&p=256436&viewfull=1#post256436)!
Wiki Tutorial With Full C++ Source Code
I provide you with the entire C++ code for my custom UMG component shown in the video above!
Rama’s Wiki on Custom UMG Components With Custom Render Code
**Custom Slate C++ Render Code**
Here's the custom Slate render code that I wrote that works with UMG's Render Transform system!
```
int32 SSoftEdgeImage::OnPaint( const FPaintArgs& Args, const FGeometry& AllottedGeometry, const FSlateRect& MyClippingRect, FSlateWindowElementList& OutDrawElements, int32 LayerId, const FWidgetStyle& InWidgetStyle, bool bParentEnabled ) const
{
#if SLATE_HD_STATS
SCOPE_CYCLE_COUNTER( STAT_SlateOnPaint_SSoftEdgeImage );
#endif
const FSlateBrush* ImageBrush = Image.Get();
if ((ImageBrush != nullptr) && (ImageBrush->DrawAs != ESlateBrushDrawType::NoDrawType))
{
const bool bIsEnabled = ShouldBeEnabled(bParentEnabled);
const uint32 DrawEffects = bIsEnabled ? ESlateDrawEffect::None : ESlateDrawEffect::DisabledEffect;
const FColor FinalColorAndOpacity( InWidgetStyle.GetColorAndOpacityTint() * ColorAndOpacity.Get().GetColor(InWidgetStyle) * ImageBrush->GetTint( InWidgetStyle ) );
//For Thickness
for (int32 v = 0; v < Thickness; v++ )
{
//Adjusted Local Size
FVector2D AdjustedSize =
FVector2D(
AllottedGeometry.GetLocalSize().X - v*2,
AllottedGeometry.GetLocalSize().Y - v*2
);
//Local Size and Translation
FPaintGeometry PaintGeom =
AllottedGeometry.ToPaintGeometry(
FVector2D(v,v), //Local Translation
AdjustedSize, //Local Size
1 //Local Scale
);
FSlateDrawElement::MakeBox(
OutDrawElements, //Out
LayerId,
PaintGeom, //Paint Geom
ImageBrush, //Brush
MyClippingRect, //Clip
DrawEffects,
FinalColorAndOpacity //Color and Opacity
);
} //For loop
}
return LayerId;
}
```
Enjoy!
:)
Rama