Pass parameters on CreateWidget on C++

Hi,

During CreateWidget, How can I pass parameters before Initiallize is called?

I would like to have something similar to SpawnDeferred but for Widgets.

Edit:
I know how to do it using blueprints but I don’t know how to do it on C++

Cheers,

Hello!

To do this, you have to create a variable in your widget, and turn on instance editable and expose on spawn.

After that, you’ll see the new parameter wherever you spawn the widget.
If it doesn’t show up automatically, you can refresh the node by right clicking and selecting refresh nodes.

332559-passparamtowidget2.jpg

If you have any questions please let me know :slight_smile:

Ah, sorry for the misunderstanding. Hopefully one of the other kind folks on the forum can help you

Thanks for the answer. Sorry, I forgot to mention that I wanted it on C++, I only set the category of the question to C++.

I already knew about the way blueprint does it.

Thanks again for your kind response.

Just in case someone is interested.

I needed to do some dynamic creation of other Widgets. I normally do so on Initialize method but since it needed variables passed right after creation, they weren’t available when Initialize() was called.

What I did, was having a Setter for that variables and create the dynamic content when they are set or do it on initialized if they are already set (they can be set if it’s from a Blueprint instance that already has values).

bool UCharacterCreatorWidget::Initialize()
{
	if (Super::Initialize())
	{
		ReloadFromCharacterCreator();
		return true;
	}
	return false;
}

void UCharacterCreatorWidget::SetCharacterCreator(UCharacterCreator* NewCharacterCreator)
{
	CharacterCreator = NewCharacterCreator;
	ReloadFromCharacterCreator();
}
    
 void UCharacterCreatorWidget::ReloadFromCharacterCreator()
{
     //Create widgets based on values of CharacterCreator
     ...
 }
1 Like