A strange problem about the UMG module

At first sorry for my bad English.
I create a C++ HUD class like this

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

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/HUD.h"
#include "MyHUD.generated.h"


class UUserWidget;
UCLASS()
class NETWORKTESTPROJECT_API AMyHUD : public AHUD
{
	GENERATED_BODY()
protected:
	UPROPERTY(EditDefaultsOnly,BlueprintReadOnly,Category="Widgets")
	TSubclassOf<UUserWidget> UserWidgetClass;
	UUserWidget* UserWidget = nullptr;

};

It cause Link Error.And I search online and find that i need to include UMG module to fix it.
I have similar code in my last project and I never include the UMG module but my last project works well.
And I finnaly found that if you create a subclass of UUserwidget like

#pragma once
#include "CoreMinimal.h"
#include "Blueprint/UserWidget.h"
#include "MyUserWidget.generated.h"
UCLASS()
class NETWORKTESTPROJECT_API UMyUserWidget : public UUserWidget
{
	GENERATED_BODY()
	
};

You do not need include UMG module but work well!
WHY??