Widget variable keeps resetting in blueprint on compile

Hi. I have a player controller class on which i have created a pointer of type Widget. When i create a blueprint based off my code and try to assign a Widget_blueprint (previously created) into it and compile the variable always gets reset to none. I Don’t know what i am doing wrong. Here’s My Code

MyPlayerController.h

// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/PlayerController.h"
#include "MyPlayerController.generated.h"

/**
 * 
 */
UCLASS()
class DARKHORSEUNREAL_API AMyPlayerController : public APlayerController
{
	GENERATED_BODY()

public:
	
	//Constructor
	AMyPlayerController();

	//Begin Play Function
	virtual void BeginPlay() override;

	//Tick Function
	virtual void Tick(float DeltaTime) override;

	UPROPERTY(EditAnywhere)
	class UUserWidget* InfoWidget;
	
};

MyPlayerController.cpp

// Fill out your copyright notice in the Description page of Project Settings.

#include "MyPlayerController.h"
#include "Blueprint/UserWidget.h"

AMyPlayerController::AMyPlayerController()
{
	// Set this character to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
	PrimaryActorTick.bCanEverTick = true;

}

void AMyPlayerController::BeginPlay()
{
	Super::BeginPlay();

	if (InfoWidget)
	{
		InfoWidget->AddToViewport();
	}
}

void AMyPlayerController::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);
}

did you set the variable on beginplay or constructor?
try setting it on constructor

I have just created a pointer in the c++ code. and i am creating a blueprint off the code and then assigning the widget blueprint into the variable through blueprint.

what event/function are you using on blueprint to save the reference?
Maybe your .cpp beginplay is already getting executed before you set your variable
try setting it on the constructor
Send a screenshot of the blueprint

I am having this exact same issue with version 4.25.4. Did you ever find a resolution for this?