Hi! Guys.
Now, I am testing UMyWidget with UMG and C++ by UUserWidget.
- 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”
- I made Widget Blueprint name ‘MyTestWidget’.
I don’t anything in GRAPH tab.
-
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; -
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.
}
}
}
}
- 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