How to change/bind/access UMG Variables in c++

Good Day, I have been stuck in this quandary for a few hours now. It feels like it should be rather simple, yet I am hitting a snag somewhere, any assistance would be appreciated.

My overall goal, is to manipulate variables that reside within a Widget (Created in the Unreal Engine UI) in my c++ code.

I created a c++ class that inherits from UUserWidget

#pragma once

#include "CoreMinimal.h"
#include "Blueprint/UserWidget.h"
#include "CountdownTimerWidget.generated.h"

/**
 * 
 */
UCLASS()
class THEPIT_API UCountdownTimerWidget : public UUserWidget
{
	GENERATED_BODY()

public:
	virtual void NativeConstruct() override;
	void SetCountdownEventTimerTime(float TimeValue);
	
	UPROPERTY(EditAnywhere, meta = (BindWidget))
	class UTextBlock* CountdownEventTimer;
protected:
	virtual void NativeTick(const FGeometry& MyGeometry, float InDeltaTime) override;
};

here I set the follwing binding to a variable I have made in the UMG widget:

class UTextBlock* CountdownEventTimer;

I created the widget in the unreal engine UI, during creation, I selected my c++ class as the parent class of the newfound widget.
After creating the canvas in the widget, I added a text block and named the variable the same as what is found in the c++ class. CountdownEventTimer

Then, in the constructor of my primary character c++ file, I attempt to create an instance of the UCountdownTimerWidget class and add this widget to the viewport:

	if (UCountdownTimerWidget* CountdownWidget = CreateWidget<UCountdownTimerWidget>(Cast<APlayerController>(Controller), UCountdownTimerWidget::StaticClass()))
	{
		CountdownWidget->AddToViewport();
	}

This code is executed as I expect when I hit the break points during runtime (one oddity, is that the variable CountdownEventTimer is NULL at this point, though I assumed this would be set after render in the viewport).

However, when this line runs, nothing ever appears on the viewport displaying the widget.

Additionally,
I have a global event that performs an action every 30 seconds, and this widget is going to be part of the countdown timer displaying when the event is going to happen, hence the setter in the UCountdownTimerWidget class:

void SetCountdownEventTimerTime(float TimeValue);

This setter does the following:

void UCountdownTimerWidget::SetCountdownEventTimerTime(float TimeValue)
{
	if (CountdownEventTimer)
	{
		const FString TimeString = FString::SanitizeFloat(TimeValue);
		const FText TimeStringText = FText::FromString(TimeString);
		CountdownEventTimer->SetText(TimeStringText);
	}
}

(NOTE - The timer value I pass is a float, so I must perform this unique serialization into a string)

This line is called, CountdownEventTimer is NULL so the if condition is never satisfied, thus my value is never set.

The problem is 2 parts:

  1. How to render the widget to the viewport so it is displayed
  2. How do I change this variable since its seems to be NULL and at what point is the value set?

Additional Details:

  1. Here is an image of the Countdownevent_BP which is the widget (showing the parent class as the proper class I created in c++

    I created this BP by right clicking → User Interface → Widget Blueprint → Selecting my class:

If I change the variable in the c++ to something else other than the demanded name, the blueprint fails to compile:
i.e.

class UTextBlock* CountdownEventTimerB;

Within Rider (The editor I use), I can see the blueprint class as the derived blueprint class, make it seem like everything is set correctly:

What am I doing wrong here? I feel as if I have been going in YouTube tutorial/UE forum circles with nothing working to perform this (seemingly simple) operation.

as i remembered there is different order when its execute constructor on c++ version and on blueprint version.
please type this code like this

UCountdownTimerWidget* CountdownWidget = CreateWidget(Cast(Controller), UCountdownTimerWidget::StaticClass());
if (CountdownWidget )
{
UE_LOG(LogTemp, Warning, TEXT(“work fine”) );
CountdownWidget->AddToViewport();
}else{
UE_LOG(LogTemp, Error, TEXT(“CountdownWidget is nullptr”) );
}
if show error i think the problem is on constructor . i think its execute constructor version before even see bindwidget that will bind later on blueprint version

Thank you for the reply,

If I attempt to create the CountdownWidget local variable in the fashion you outlined above, I get an error:

Cannot initialize local variable 'CountdownWidget' of type UCountdownTimerWidget* with UUserWidget*

It seems that the CreateWidget function demands a cast during object creation:

	UUserWidget* CountdownWidget = CreateWidget<UUserWidget>(Cast<APlayerController>(Controller), UCountdownTimerWidget::StaticClass());

or

UCountdownTimerWidget* CountdownWidget = CreateWidget<UCountdownTimerWidget>(Cast<APlayerController>(Controller), UCountdownTimerWidget::StaticClass()))

Creating some conditional logic akin to what you have above:

	UUserWidget* CountdownWidget = CreateWidget<UUserWidget>(Cast<APlayerController>(Controller), UCountdownTimerWidget::StaticClass());
	// if (UCountdownTimerWidget* CountdownWidget = CreateWidget<UCountdownTimerWidget>(Cast<APlayerController>(Controller), UCountdownTimerWidget::StaticClass()))
	if (CountdownWidget) {
		CountdownWidget->AddToViewport();
	} else
	{
		UE_LOG(LogTemp, Error, TEXT("CountdownWidget is not set"));
	}

The CountdownWidget is created and I hit the line:

CountdownWidget->AddToViewport();

(Debugging in Rider, I hit my break point here, the CountdownWidget object is created, but the CountdownEventTimer is NULL still:

I.e. the binding from the header file for the class:

	UPROPERTY(EditAnywhere, meta = (BindWidget))
	class UTextBlock* CountdownEventTimer;

So I do not hit the UE_LOG in the conditional statement, so it seems the object is being created. Yet nothing appears in the Viewport and any attempt to access the CoutndownEventTimer value in the setter is non-functional as the value is NULL yet.