RealDocs

UCanvasPanel::AddChildToCanvas

function UMG Blueprint Since 4.0
#include "Components/CanvasPanel.h"
Access: public Specifiers: UFUNCTIONBlueprintCallable

Description

Adds a widget as a new child of the canvas panel and returns its slot so you can set its position, size, and anchors.

Caveats & Gotchas

  • If Content already belongs to another panel, it is automatically removed from its previous parent — no need to call RemoveFromParent yourself first.
  • Returns nullptr if Content is null; it does not assert or crash on a bad argument.

Signature

UCanvasPanelSlot* AddChildToCanvas(UWidget* Content)

Parameters

Name Type Description Default
Content UWidget* The widget to add as a new child of the canvas.

Return Type

UCanvasPanelSlot*

Example

Add and position a widget C++
UCanvasPanelSlot* Slot = CanvasPanel->AddChildToCanvas(MyWidget);
if (Slot)
{
	Slot->SetPosition(FVector2D(100.f, 50.f));
	Slot->SetSize(FVector2D(200.f, 40.f));
}

Tags

Version History

Introduced in: 4.0

Version Status Notes
5.6 stable

Feedback

Was this helpful?

Suggest an edit

Select a field above to begin editing.