# Widget instance is null

**URL:** <https://forums.unrealengine.com/t/widget-instance-is-null/861176>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine, question\
**Created:** [April 6, 2023, 11:30am UTC](https://forums.unrealengine.com/t/widget-instance-is-null/861176 "2023-04-06T11:30:32Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![g.zahariev](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@g.zahariev](https://forums.unrealengine.com/u/g.zahariev)\
**Post date:** [April 6, 2023, 11:30am UTC](https://forums.unrealengine.com/t/widget-instance-is-null/861176/1 "2023-04-06T11:30:32Z")

</div>

MyWidgetInstance = CreateWidget(GetWorld(), WidgetClass);

MyWidgetInstance is null  
UMyUserWidget is my actual widget name

---

<div class="post-metadata">

**Author:** ![Tuerer](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/tuerer/32/1008648_2.png) [@Tuerer](https://forums.unrealengine.com/u/Tuerer)\
**Post date:** [April 6, 2023, 12:16pm UTC](https://forums.unrealengine.com/t/widget-instance-is-null/861176/2 "2023-04-06T12:16:35Z")

</div>

Did you set `WidgetClass` either in the blueprint or via ConstructionHelpers?

---

<div class="post-metadata">

**Author:** ![g.zahariev](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@g.zahariev](https://forums.unrealengine.com/u/g.zahariev)\
**Post date:** [April 6, 2023, 12:19pm UTC](https://forums.unrealengine.com/t/widget-instance-is-null/861176/3 "2023-04-06T12:19:41Z")

</div>

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

#include “Components/TextBlock.h”  
#include “MyUserWidget.h”

void UMyUserWidget::NativeConstruct()  
{  
Super::NativeConstruct();

```
// ItemTitle can be nullptr if we haven't created it in the
// Blueprint subclass
if (ItemTitle)
{
	ItemTitle->SetText(FText::FromString(TEXT("Hello world!")));
}

```

}

void UMyUserWidget::Update()  
{

```
// ItemTitle can be nullptr if we haven't created it in the
// Blueprint subclass

	ItemTitle->SetText(FText::FromString(TEXT("Hello!")));

```

}

This part works and display hello world correctly on the screen.

---

<div class="post-metadata">

**Author:** ![ScrewdriverHyena](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/screwdriverhyena/32/679006_2.png) [@ScrewdriverHyena](https://forums.unrealengine.com/u/ScrewdriverHyena)\
**Post date:** [April 6, 2023, 12:31pm UTC](https://forums.unrealengine.com/t/widget-instance-is-null/861176/4 "2023-04-06T12:31:05Z")

</div>

But where are you setting `WidgetClass`?

---

<div class="post-metadata">

**Author:** ![g.zahariev](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@g.zahariev](https://forums.unrealengine.com/u/g.zahariev)\
**Post date:** [April 6, 2023, 12:34pm UTC](https://forums.unrealengine.com/t/widget-instance-is-null/861176/5 "2023-04-06T12:34:24Z")

</div>

It’s a variable the I have declared in the actor class.

```
UPROPERTY(EditAnywhere, Category = "Widgets")
	TSubclassOf<UMyUserWidget> WidgetClass;

```

Where should I set it and how?

---

<div class="post-metadata">

**Author:** ![ScrewdriverHyena](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/screwdriverhyena/32/679006_2.png) [@ScrewdriverHyena](https://forums.unrealengine.com/u/ScrewdriverHyena)\
**Post date:** [April 6, 2023, 12:41pm UTC](https://forums.unrealengine.com/t/widget-instance-is-null/861176/6 "2023-04-06T12:41:40Z")

</div>

Create a Blueprint instance of your Actor, and you’ll see that `Widget Class` will be available as a property of the blueprint that you can modify however you wish.

---

<div class="post-metadata">

**Author:** ![g.zahariev](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@g.zahariev](https://forums.unrealengine.com/u/g.zahariev)\
**Post date:** [April 6, 2023, 12:43pm UTC](https://forums.unrealengine.com/t/widget-instance-is-null/861176/7 "2023-04-06T12:43:50Z")

</div>

[Learn Unreal Engine (with C++) - Full Course for Beginners - YouTube](https://youtu.be/LsNW4FPHuZE?t=3076) - I guess that his what you mean?

---

<div class="post-metadata">

**Author:** ![ScrewdriverHyena](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/screwdriverhyena/32/679006_2.png) [@ScrewdriverHyena](https://forums.unrealengine.com/u/ScrewdriverHyena)\
**Post date:** [April 6, 2023, 12:47pm UTC](https://forums.unrealengine.com/t/widget-instance-is-null/861176/8 "2023-04-06T12:47:13Z")

</div>

Yes, exactly.

---

<div class="post-metadata">

**Author:** ![g.zahariev](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@g.zahariev](https://forums.unrealengine.com/u/g.zahariev)\
**Post date:** [April 6, 2023, 12:48pm UTC](https://forums.unrealengine.com/t/widget-instance-is-null/861176/9 "2023-04-06T12:48:43Z")

</div>

Thanks! From time to time I use ChatGPT, but it gets things really wrong. Is it possible to set this in code or is it better to use the video approach?

---

<div class="post-metadata">

**Author:** ![ScrewdriverHyena](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/screwdriverhyena/32/679006_2.png) [@ScrewdriverHyena](https://forums.unrealengine.com/u/ScrewdriverHyena)\
**Post date:** [April 6, 2023, 12:49pm UTC](https://forums.unrealengine.com/t/widget-instance-is-null/861176/10 "2023-04-06T12:49:55Z")

</div>

From what I’m aware of, no. The best way to get the widget class is through creating the blueprint instance and setting it there.
