Why is myWidgetClass returen NULL?

Hi! Guys.

Now, I am testing UMyWidget with UMG and C++ by UUserWidget.

  1. I made MyWidget Class.

#pragma once

#include “Blueprint/UserWidget.h”

#include “MyWidget.generated.h”

/**
*
*/

UCLASS()
class REALGOLF_API UMyWidget : public UUserWidget
{
GENERATED_BODY()

};

#include “WidgetTest.h”

#include “MyWidget.h”

  1. I made Widget Blueprint name ‘MyTestWidget’.

36314-mywidget2.png

I don’t anything in GRAPH tab.

  1. I Modified MyController.h

    // The class that will be used for the MyWidgetUI
    UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = “Player, HUD and UI”)
    TSubclassOf myWidgetUIClass;

    // The instance of the MyWidgetUI Widget
    UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = “Player, HUD and UI”)
    class UMyWidget* myWidget;

  2. I modified MyController.cpp

#include “WidgetTest.h”

#include “MyWidget.h”

#include “MyController.h”

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

// Only create the UI on the local machine (dose not excist on the server.)
if (IsLocalPlayerController())
{
	if (myWidgetUIClass) // Check the selected UI class is not NULL
	{
		if (!myWidget) // If the widget is not created and == NULL
		{
			myWidget= CreateWidget<UMyWidget>(this, myWidgetUIClass); // Create Widget
			if (!myWidget)
				return;
			myWidget->AddToViewport(); // Add it to the viewport so the Construct() method in the UUserWidget:: is run.
			myWidget->SetVisibility(ESlateVisibility::Hidden); // Set it to hidden so its not open on spawn.
		}
	}
}

}

  1. I compile and execute. But can’t display Widget.
    myWidgetUIClass is null pointer.

Why is myWidgetUIClass NULL.

What’s wrong?

Help me please.

Engine version : 4.7.0
OS : Windows7

Check log, you might have info there

Where can i find log?

I can’t find log about widget blueprint in log windows.

I think that widget blueprint not executed.

How can i call widget blueprint.

Having this same issue.

So any advice ?

I eventually got this to work. It turns out that BeginPlay might not be called on the client, which is where you want to create your widget. So, I moved my widget initialization code to ClientGameStarted_Implementation of my custom PlayerController. There are probably other methods you could initialize your widget in, like PostInitializeComponents.

See my answer.