Example #1
0
void UUserWidget::Initialize()
{
	// If it's not initialized initialize it, as long as it's not the CDO, we never initialize the CDO.
	if ( !bInitialized && !HasAnyFlags(RF_ClassDefaultObject) )
	{
		bInitialized = true;

		// Only do this if this widget is of a blueprint class
		UWidgetBlueprintGeneratedClass* BGClass = Cast<UWidgetBlueprintGeneratedClass>(GetClass());
		if ( BGClass != nullptr )
		{
			BGClass->InitializeWidget(this);
		}

		// Map the named slot bindings to the available slots.
		WidgetTree->ForEachWidget([&] (UWidget* Widget) {
			if ( UNamedSlot* NamedWidet = Cast<UNamedSlot>(Widget) )
			{
				for ( FNamedSlotBinding& Binding : NamedSlotBindings )
				{
					if ( Binding.Content && Binding.Name == NamedWidet->GetFName() )
					{
						NamedWidet->ClearChildren();
						NamedWidet->AddChild(Binding.Content);
						return;
					}
				}
			}
		});

		// TODO Find a way to remove the bindings from the table.  Currently they're still needed.
		// Clear the named slot bindings table.
		//NamedSlotBindings.Reset();
	}
}
Example #2
0
bool UUserWidget::Initialize()
{
	// If it's not initialized initialize it, as long as it's not the CDO, we never initialize the CDO.
	if ( !bInitialized && !HasAnyFlags(RF_ClassDefaultObject) )
	{
		bInitialized = true;

		// Only do this if this widget is of a blueprint class
		UWidgetBlueprintGeneratedClass* BGClass = Cast<UWidgetBlueprintGeneratedClass>(GetClass());
		if ( BGClass != nullptr )
		{
			BGClass->InitializeWidget(this);
		}

		if ( WidgetTree == nullptr )
		{
			WidgetTree = NewObject<UWidgetTree>(this, TEXT("WidgetTree"));
		}

		// Map the named slot bindings to the available slots.
		WidgetTree->ForEachWidget([&] (UWidget* Widget) {
			if ( UNamedSlot* NamedWidet = Cast<UNamedSlot>(Widget) )
			{
				for ( FNamedSlotBinding& Binding : NamedSlotBindings )
				{
					if ( Binding.Content && Binding.Name == NamedWidet->GetFName() )
					{
						NamedWidet->ClearChildren();
						NamedWidet->AddChild(Binding.Content);
						return;
					}
				}
			}
		});

		return true;
	}
	return false;
}