# CreateWidget() not working

**URL:** <https://forums.unrealengine.com/t/createwidget-not-working/347557>\
**Category:** Platform & Builds\
**Tags:** unreal-engine, UE4, question\
**Created:** [February 15, 2016, 4:48pm UTC](https://forums.unrealengine.com/t/createwidget-not-working/347557 "2016-02-15T16:48:41Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![godisntheradio](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@godisntheradio](https://forums.unrealengine.com/u/godisntheradio)\
**Post date:** [February 15, 2016, 4:48pm UTC](https://forums.unrealengine.com/t/createwidget-not-working/347557/1 "2016-02-15T16:48:41Z")

</div>

i have:

A blueprint Widget with health display;

A Hud derived class.

i’m trying to “attach” this widget to this hud class following this tutorial

> **[A new, community-hosted Unreal Engine Wiki](https://forums.unrealengine.com/t/a-new-community-hosted-unreal-engine-wiki/141494)**
>
> After over a year in maintenance mode, the official Unreal Engine Wiki is now permanently offline. These resources now live on a new community-run Unreal Engine Community Wiki — ue4community.wiki! You will be able to find content from the official...

there are two problems:  
1.  
.h

```
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Widgets")
		TSubclassOf<class UUserWidget> GameHUD;

	UUserWidget* m_gameHud;

```

.cpp

```
if (GameHUD)
	{
		GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Blue, TEXT("it works"));
		m_gameHud = CreateWidget<UUserWidget>(GetWorld()->GetGameInstance(), GameHUD);
		if (m_gameHud)
		{
			m_gameHud->AddToViewport();
		}
	}

```

the if(GameHUD) is returning false, to create a widget you have to pass a pointer to widget class(?) and apparently it’s not working like in the tutorial, plus, if i take this if out, the editor crashes e doesn’t even open afterwards.

2.in the tutorial the widget is attached to a player controller, so i don’t know if i’m supposed to hud class control widgets.

---

<div class="post-metadata">

**Author:** ![Invius](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Invius](https://forums.unrealengine.com/u/Invius)\
**Post date:** [June 30, 2016, 3:07pm UTC](https://forums.unrealengine.com/t/createwidget-not-working/347557/2 "2016-06-30T15:07:22Z")

</div>

Same problem here!!!

---

<div class="post-metadata">

**Author:** ![TheSubZer0](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@TheSubZer0](https://forums.unrealengine.com/u/TheSubZer0)\
**Post date:** [July 27, 2019, 11:07pm UTC](https://forums.unrealengine.com/t/createwidget-not-working/347557/3 "2019-07-27T23:07:39Z")

</div>

dont set owning player to get player controller give it “dont specify”
