C++ Dirty Fix
By extending the original SScrollBox and UScrollBox classes, it’s possible to override the method causing the problem and fix it.
Add these modules to Source/YourProjectName/YourProjectName.Build.cs, at PublicDependencyModuleNames
"SlateCore", "Slate", "UMG"
To YourProjectName.h, add
#include "Engine.h" // already on file
#include "SlateBasics.h" // add this line after that
Add these code files to fix the problem on the Slate ScrollBox widget:
SCustomScrollBox.h
#pragma once
#include "Widgets/Layout/SScrollBox.h"
/**
* Fixes ScrollBox bug of not registering TouchStarted event
*/
class YOURPROJECTNAME_API SCustomScrollBox : public SScrollBox
{
public:
virtual FReply OnTouchStarted(
const FGeometry& MyGeometry,
const FPointerEvent& InTouchEvent) override;
};
SCustomScrollBox.cpp
#include "MineSweeper.h"
#include "SCustomScrollBox.h"
FReply SCustomScrollBox::OnTouchStarted(const FGeometry& MyGeometry, const FPointerEvent& InTouchEvent)
{
return FReply::Handled();
}
To be able to use the fixed Slate widget in UMG, also extend the UScrollBox class and override the method that creates the Slate widget to use our custom class.
CustomScrollBox.h
#pragma once
#include "UMG.h"
#include "Components/ScrollBox.h"
#include "CustomScrollBox.generated.h"
/**
* Fixes ScrollBox bug of not registering TouchStarted event
*/
UCLASS()
class YOURPROJECTNAME_API UCustomScrollBox : public UScrollBox
{
GENERATED_BODY()
protected:
//~ Begin UWidget Interface
virtual TSharedRef<SWidget> RebuildWidget() override;
//~ End UWidget Interface
public:
#if WITH_EDITOR
//~ Begin UWidget Interface
virtual const FText GetPaletteCategory() override;
//~ End UWidget Interface
#endif
};
CustomScrollBox.cpp
#include "MineSweeper.h"
#include "SCustomScrollBox.h"
#include "CustomScrollBox.h"
#define LOCTEXT_NAMESPACE "UMG"
TSharedRef<SWidget> UCustomScrollBox::RebuildWidget()
{
MyScrollBox = SNew(SCustomScrollBox)
.Style(&WidgetStyle)
.ScrollBarStyle(&WidgetBarStyle)
.Orientation(Orientation)
.ConsumeMouseWheel(ConsumeMouseWheel);
for (UPanelSlot* PanelSlot : Slots)
{
if (UScrollBoxSlot* TypedSlot = Cast<UScrollBoxSlot>(PanelSlot))
{
TypedSlot->Parent = this;
TypedSlot->BuildSlot(MyScrollBox.ToSharedRef());
}
}
return BuildDesignTimeWidget(MyScrollBox.ToSharedRef());
}
#if WITH_EDITOR
const FText UCustomScrollBox::GetPaletteCategory()
{
return LOCTEXT("User Created", "User Created");
}
#endif
This CustomScrollBox will be found in the User Created category of the Palette in the UMG Editor as Custom Scroll Box.
As it’s a child of the original ScrollBox, you can safely replace ScrollBoxes and its variables in your Blueprints. Easily replace existing ScrollBoxes in the Design mode by selecting the Custom Scroll Box in the Palette then right clicking on the current ScrollBox in the hierarchy and selecting Replace With…>Custom Scroll Box. The only drawback is that you’ll lose any customization done in the replaced ScrollBox’s Details panel (Style, Visibility etc).