반응형

 

 

In Unreal Engine blueprint widget, you can create different shapes through an array of points. There is no line drawing in the user widget with an array of points in C++, so we will use UWidgetBlueprintLibrary. In order to draw the shape, we must use UWidgetBlueprintLibrary::DrawLines. And then another trouble awaits us — we cann’t override OnPaint.

All animals are equal, but some animals are more equal than others.

So, we’ll just override NativePaint.

int32 UPaintWidget::NativePaint(const FPaintArgs &Args, 
const FGeometry &AllottedGeometry, const FSlateRect &MyCullingRect, FSlateWindowElementList &OutDrawElements, int32 LayerId, const FWidgetStyle &InWidgetStyle, bool bParentEnabled) const
{
    Super::NativePaint(Args, AllottedGeometry, MyCullingRect,  OutDrawElements, LayerId, InWidgetStyle, bParentEnabled);    FPaintContext Context(AllottedGeometry, MyCullingRect, OutDrawElements, LayerId, InWidgetStyle, bParentEnabled);    UWidgetBlueprintLibrary::DrawLines(Context, Points, FLinearColor::Blue, true, 10.0f);    return LayerId + 1;
}

We simply created a variable of the array of points in the class and by updating this array, our shape is also updated.

The complete code of this project is available on GitHub.

 

 

https://medium.com/@qerrant/gesture-recognizer-for-unreal-engine-24422d5868ba

반응형

+ Recent posts