im trying to move UI blueprint code and wondering if i have coded it right

im not sure if i have coded it right or but i definatly feel like im heading the right way.
for more info on the code

Parent: its a variable that is referencing another UI (UI_W)
Crosshair: its a funtion in UI_W

image

Hi @emir143 ,

I don’t know if by now you already find the answer or not.
your Cpp function is almost correct, however, there are something you have to do, for that, I will try to write a simple “how to” bind button correctly based on your Blueprint picture.

You also have to use UFUNCTION for the function you want to bind and your HandleButtonClick function should be like this:

.h
UFUNCTION()
void HandleButtonClick();

.cpp
void UInventoryUI::HandleButtonClick()
{
	if (IsValid(UiCpp)) // you can also just do this if -> if(UiCpp){. . .}
	{
		UiCpp->CrosshairFunction();
	}
}

then you also need to bind the Button in the native construct:

.h
virtual void NativeConstruct() override;

.cpp
void UInventoryUI::NativeConstruct()
{
	Super::NativeConstruct();

	Close_Buttone->OnClicked.AddUniqueDynamic(this, &UInventoryUI::HandleButtonClick);
}

for the button itself, also make sure it already got the correct UPROPERTY and same name with the WidgetBP:

UPROPERTY(meta = (BindWidget))
UButton* Close_Buttone;

Lastly, don’t forget to reparent your Widget blueprint to your custom UserWidget Cpp class. I hope i’m not missing a step.