I’ve been trying to make a function that swaps a child widget with another child widget, so I looked through the source code and found the ReplaceChildAt function and made the function below to expose it to blueprints but I cannot get it to work I have confirmed that its returning true, yet no change is occurring.
Does anyone know why?
MyWidgetFunctionLibrary
.H
#include "CoreMinimal.h"
#include "Kismet/BlueprintFunctionLibrary.h"
#include "MyWidgetFunctionLibrary.generated.h"
/**
*
*/
class UPanelWidget;
class UWidget;
class UVerticalBox;
UCLASS()
class MYTABLELOADER_API UMyWidgetFunctionLibrary : public UBlueprintFunctionLibrary
{
GENERATED_BODY()
public:
UFUNCTION(BlueprintCallable, DisplayName = "Replace Child Widget At Index", Category = "Special Widget Functions")
static bool ReplaceChildWidgetAt(UPanelWidget* Parent, UWidget* NewChild, int32 Index);
};
.CPP
#include "MyWidgetFunctionLibrary.h"
#include "Components/PanelWidget.h"
bool UMyWidgetFunctionLibrary::ReplaceChildWidgetAt(UPanelWidget* Parent, UWidget* NewChild, int32 ChildIndex)
{
return Parent->ReplaceChildAt(ChildIndex, NewChild);
}
UPanelWidget
Definition of ReplaceChildAt function
.cpp
bool UPanelWidget::ReplaceChildAt(int32 Index, UWidget* Content)
{
if ( Index < 0 || Index >= Slots.Num() )
{
return false;
}
UPanelSlot* PanelSlot = Slots[Index];
PanelSlot->Content = Content;
if ( Content )
{
Content->Slot = PanelSlot;
}
PanelSlot->SynchronizeProperties();
return true;
}
Photo of widgets and blueprints
Mod widget
Load order page