ReplaceChildAt function not working on child widget in UMG

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

r/unrealengine - ReplaceChildAt function not working on child widget in UMG

r/unrealengine - ReplaceChildAt function not working on child widget in UMG

Load order page

r/unrealengine - ReplaceChildAt function not working on child widget in UMG

r/unrealengine - ReplaceChildAt function not working on child widget in UMG

I just ran into the same issue while trying to use the same logic as ReplaceChildAt in my own C++ code. From my understanding the changes made to the slots are never passed down to the underlying slate widget. The function required to update the PanelSlot only exist on the child classes (-> e.g. UVerticalBoxSlot::BuildSlot) and all access points to call this from outside are protected in some way. (-> e.g. MyVerticalBox inside UVerticalBox and UPanelWidget::OnSlotAdded). I need this for my subtitle plugin, so I’ll send an update with how I fixed this. (Presumably just custom panel widgets.)

Here is a working child replacement function: Modified VerticalBox, however this also requires a custom VerticalBoxSlot. (You don’t need all the code, there is some accessibility stuff woven in.)
The easier “classic” BP option would be to get an array of pointers to all children, remove the child you don’t want from the array, clear all children from the panel, then add each remaining child again.

Edit: updated VerticalBox Link