How to get widget from Panel Slot?

How to get widget from Panel Slot?

You can *Get Child At *if you know the index. Otherwise, you need to be more specific regarding what you’re trying to do.

How to Connect

It won’t work like that. A slot is already a child, kind of. Just use a Canvas Panel -> Get Child.

The above widget has a *Canvas Panel *which, in turn, has some other widgets nesting in there. You can Get Child At from the *Canvas Panel *(or any panel widget) and then treat this child as a slot - this gives you access to anchors, padding and all the slot goodies.

How to Connect ,get widget from Panel Slot

This will not work, I explained above. I do not understand what you’re trying to do but here is what I think you’re trying to do:

If this does not help - consider using Google Translate if you do not feel confident enough writing in English. Or try asking your question here: 简体中文 (Simplified Chinese) - Unreal Engine Forums. I see some activity on the Answer Hub in your language, too. Last resort - try that

get the Target Image , warning , why?

Need Panel slot type, no change

This cast will always fail, your custom Target Image widget does not inherit from Panel Slot.

Need Target Image widget from Panel Slot ,how to set

As far as I know slots do not care what is inside of them. They simply contain layout information of a panel. You can’t access widgets from an UMG slot.

Я не хочу создавать лишние переменные и поэтому делаю UserWidget наследованием. А чтобы сделать наследованием без лишних элементов требуется функция добавления в корень UserWidget.

PreConstruct: Код генерации интерфейса и добавление это в корень UserWidget.
Переменные родителя

PreConstruct Берем из корня UserWidget интерфейс и вставляем в генерируемый интерфейс.
Переменные родителя
Переменные наследника


unfortunately you can’t do it in blueprint, but you can do it if you use C++.

In Blueprint you can access a slot if you have a reference to a widget added to the canvas. You can see how to do it on the example bellow. In Construct Event I create an Image, which is then added to the canvas. In tick I set a new position to the image inside the canvas.

In Blueprint you can’t do things in revers - get widget from a slot reference, although in reality under the hood slot remembers which widget it contains.

Bellow you can see example code in C++ .

In MySuperWidget.h

class UTexture2D* Icon;

UPROPERTY(meta = (BindWidget))
UCanvasPanel* Canvas;

In MySuperWidget.cpp

/* Create Image, add it to canvas and store reference UCanvasPanelSlot /
image = NewObject(this, UImage::StaticClass());
UCanvasPanelSlot* newSlot = Canvas->AddChildToCanvas(image);

/* If you want to access image which you store inside a newSlot /
image = Cast(newSlot->Content);

/* If you want to access canvas inside which newSlot is located /
MyCanvas = Cast(newSlot->Parent)

As you can see, you have access to the canvas of the slot via MySlot->Parent and access to a widget stored inside the slot via MySlot->Content.

It is good to know, that these variables are accessed from UPanelSlot class, which is the parent class for all U*Slot.

Hope I helped :smiley:

1 Like