# UI Button is not working...

**URL:** <https://forums.unrealengine.com/t/ui-button-is-not-working/488776>\
**Category:** UI\
**Tags:** unreal-engine, onclicked, UI, Widget, question, UMG\
**Created:** [September 14, 2021, 11:31am UTC](https://forums.unrealengine.com/t/ui-button-is-not-working/488776 "2021-09-14T11:31:36Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![shivansh\_pandey2](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/shivansh_pandey2/32/710746_2.png) [@shivansh\_pandey2](https://forums.unrealengine.com/u/shivansh_pandey2)\
**Post date:** [September 14, 2021, 11:31am UTC](https://forums.unrealengine.com/t/ui-button-is-not-working/488776/1 "2021-09-14T11:31:36Z")

</div>

I am creating a user widget which generates random number and I followed this video from YouTube:  
[https://www.youtube.com/watch?v=bWoew0fa\_xA&t=731s](https://www.youtube.com/watch?v=bWoew0fa_xA&t=731s)

but the problem is that my button is not responding when I am trying to click it do not generates a random  
number but when I call function OnClick with the blueprint it works so How to get it working with the c++  
this is my CustomWidget.h file:

```
#pragma once

#include "CoreMinimal.h"
#include "Blueprint/UserWidget.h"
#include <Runtime/UMG/Public/Components/TextBlock.h>
#include <Runtime/UMG/Public/Components/Button.h>
#include "CustomWidget.generated.h"

/**
 * 
 */
UCLASS()
class CHAPTER5_API UCustomWidget : public UUserWidget
{
	GENERATED_BODY()
	
protected:
	UFUNCTION(BlueprintCallable)
	void GenerateRandom();

	UPROPERTY(meta = (BindWidget))
	UTextBlock* RandomNumberLabel;

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

	void NativeConstruct() override;
};

```

here is the cpp file:

```
#include "CustomWidget.h"

void UCustomWidget::NativeConstruct()
{
	Super::NativeConstruct();

	GenerateRandom();

	GenerateButton->OnClicked.AddUniqueDynamic(this, &UCustomWidget::GenerateRandom);
}

void UCustomWidget::GenerateRandom()
{
	int32 RandomNumber = FMath::FRandRange(0, 100);

	RandomNumberLabel->SetText(FText::AsNumber(RandomNumber));

}

```

then i blueprinted this class, and created UI components likw button, textbox etc…  
then in the level blueprint I created widget instance as shown in the tutorial but the button still didn’t worked.

---

<div class="post-metadata">

**Author:** ![Kehel18](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Kehel18](https://forums.unrealengine.com/u/Kehel18)\
**Post date:** [September 17, 2021, 3:50pm UTC](https://forums.unrealengine.com/t/ui-button-is-not-working/488776/2 "2021-09-17T15:50:59Z")

</div>

Hello! Just have checked it - everything is working fine…

---

<div class="post-metadata">

**Author:** ![Ravi80335](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Ravi80335](https://forums.unrealengine.com/u/Ravi80335)\
**Post date:** [September 22, 2021, 4:41pm UTC](https://forums.unrealengine.com/t/ui-button-is-not-working/488776/3 "2021-09-22T16:41:15Z")

</div>

Did you set Parent Class?

If not, then, Open Class Settings in your Widget Blueprint, here set Parent class to your c++ customwidget class
