# Widget create blueprint runtime error

**URL:** <https://forums.unrealengine.com/t/widget-create-blueprint-runtime-error/1290357>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine, question, Blueprint\
**Created:** [September 10, 2023, 7:21pm UTC](https://forums.unrealengine.com/t/widget-create-blueprint-runtime-error/1290357 "2023-09-10T19:21:47Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![NosferatuVampir](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@NosferatuVampir](https://forums.unrealengine.com/u/NosferatuVampir)\
**Post date:** [September 10, 2023, 7:21pm UTC](https://forums.unrealengine.com/t/widget-create-blueprint-runtime-error/1290357/1 "2023-09-10T19:21:47Z")

</div>

I have simple widget to show number of items. I add it to player blueprint

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/5/8/5/5859c439a275fbb6e294c9f96a9a539b1507f44d.png)  
It’s called by other actors  
 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/0/d/2/0d24cd18c24012285bee2df2a1796832a7ac37cf.png)  
To add or remove 1 point.  
 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/d/1/f/d1f44737205b2781430b2aa885015f3869bd2b36.png)  
And it’s working good except after I click ESC and return to editor I am getting lots of errors  
 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/e/4/a/e4af63d1d1af717590ef0c5f135f35c7580a6127.png)

---

<div class="post-metadata">

**Author:** ![56legion](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/56legion/32/1194529_2.png) [@56legion](https://forums.unrealengine.com/u/56legion)\
**Post date:** [September 11, 2023, 2:22am UTC](https://forums.unrealengine.com/t/widget-create-blueprint-runtime-error/1290357/2 "2023-09-11T02:22:30Z")

</div>

> [@NosferatuVampir](#):
>
> ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/0/d/2/0d24cd18c24012285bee2df2a1796832a7ac37cf.png)

is BP\_ball is your player character?

---

<div class="post-metadata">

**Author:** ![UnrealEverything](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@UnrealEverything](https://forums.unrealengine.com/u/UnrealEverything)\
**Post date:** [September 11, 2023, 5:51am UTC](https://forums.unrealengine.com/t/widget-create-blueprint-runtime-error/1290357/3 "2023-09-11T05:51:34Z")

</div>

Seems like the UI is already destroyed when you call the `BoxPaintedBy*` events. Just check the UI for validity before setting the points.

If these points represent something like score then you should probably consider storing them in the GameState instead. Your UI should ideally not contain any game logic.

---

<div class="post-metadata">

**Author:** ![NosferatuVampir](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@NosferatuVampir](https://forums.unrealengine.com/u/NosferatuVampir)\
**Post date:** [September 11, 2023, 10:54am UTC](https://forums.unrealengine.com/t/widget-create-blueprint-runtime-error/1290357/4 "2023-09-11T10:54:16Z")

</div>

Yes

---

<div class="post-metadata">

**Author:** ![NosferatuVampir](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@NosferatuVampir](https://forums.unrealengine.com/u/NosferatuVampir)\
**Post date:** [September 11, 2023, 11:38am UTC](https://forums.unrealengine.com/t/widget-create-blueprint-runtime-error/1290357/5 "2023-09-11T11:38:26Z")

</div>

UI store logic to do +1 or -1 to items displayed in UI. Maybe you have some good guides or tutorials about GameState and its interactions with UI?

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [September 11, 2023, 11:39am UTC](https://forums.unrealengine.com/t/widget-create-blueprint-runtime-error/1290357/6 "2023-09-11T11:39:56Z")

</div>

> [@NosferatuVampir](#):
>
> UI store logic to do +1 or -1 to items displayed in UI.

The errors point here:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/0/8/6/08696a969d147e1c57ab6aed66223cf2e7c3aa47.jpeg)

You’re accessing a widget that has yet to exist, no longer exists or is not referenced properly. Think of how & when you set that `UI` reference. It’s not shown in your screenshots.

---

<div class="post-metadata">

**Author:** ![NosferatuVampir](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@NosferatuVampir](https://forums.unrealengine.com/u/NosferatuVampir)\
**Post date:** [September 11, 2023, 12:13pm UTC](https://forums.unrealengine.com/t/widget-create-blueprint-runtime-error/1290357/7 "2023-09-11T12:13:38Z")

</div>

![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/8/4/8/848dad5d549ea513638d72bf6f8828eee943a163.png)

I set it in my player blueprint (BP\_Ball is my player).  
And when I want to call a method of my UI I call it using my bp\_ball

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/c/d/d/cdd934072197ecf451857466511d34c5371c0328.png)

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [September 11, 2023, 12:27pm UTC](https://forums.unrealengine.com/t/widget-create-blueprint-runtime-error/1290357/8 "2023-09-11T12:27:01Z")

</div>

Not sure what you mean.

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/0/8/6/08696a969d147e1c57ab6aed66223cf2e7c3aa47.jpeg)

The errors complain about this specifically. You never show where it was set.

---

<div class="post-metadata">

**Author:** ![NosferatuVampir](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@NosferatuVampir](https://forums.unrealengine.com/u/NosferatuVampir)\
**Post date:** [September 11, 2023, 12:57pm UTC](https://forums.unrealengine.com/t/widget-create-blueprint-runtime-error/1290357/9 "2023-09-11T12:57:48Z")

</div>

I am sorry I just got confused. I thought that set practically meant this:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/8/4/8/848dad5d549ea513638d72bf6f8828eee943a163.png)  
What is the correct way to set it then?

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [September 11, 2023, 12:59pm UTC](https://forums.unrealengine.com/t/widget-create-blueprint-runtime-error/1290357/10 "2023-09-11T12:59:22Z")

</div>

> [@NosferatuVampir](#):
>
> What is the correct way to set it then?

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/0/3/1/0317c4a2da3b3b59c48f5d68874b5a96f3bbe1d4.png)

* * *

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/d/1/f/d1f44737205b2781430b2aa885015f3869bd2b36.png)

Essentially, this blueprint needs to know what `UI` is. Creating a ref variable but **not assigning** a value achieves little. Imagine you have a string variable but forgot to type in the text. You have a variable that _could_ hold text but is empty.

Similar to your UI var at the moment. It could refer to a widget, but which one? What if there are 4 UI widgets. Even if there is only 1, you must still assign value to the variable. That’s what the first pic does.

* * *

What you originally posted is quite confusing, actually. Especially that you say that it does work but throws errors…

Perhaps you could explain what the most important part of this thing is. The `UI -> Set Points int` what is it and how is it supposed to work? Judging by the cutoff W in the bottom right corner, we’re already inside some widget.

* * *

Perhaps you think:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/c/b/4/cb45b146a76c55e5caf42305594a579a463567fe.jpeg)

These 2 are somehow related? Because they are not. Are you trying to push in Points value into the widget _“I add it to player blueprint created in the player BP”_ in the very 1st pic you posted the thread?

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [September 11, 2023, 1:29pm UTC](https://forums.unrealengine.com/t/widget-create-blueprint-runtime-error/1290357/11 "2023-09-11T13:29:56Z")

</div>

> [@NosferatuVampir](#):
>
> And it’s working good except after I click ESC and return to editor I am getting lots of errors

I think I know what you’re doing. You’re overthinking it:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/d/2/6/d2682c0db662664fc4444b8ef47dcad94a685cbb.png)

Delete this part, and get rid of that UI variable. You already have the bits you need and this part is not necessary.

---

<div class="post-metadata">

**Author:** ![NosferatuVampir](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@NosferatuVampir](https://forums.unrealengine.com/u/NosferatuVampir)\
**Post date:** [September 11, 2023, 2:31pm UTC](https://forums.unrealengine.com/t/widget-create-blueprint-runtime-error/1290357/12 "2023-09-11T14:31:16Z")

</div>

And you are 100% correct. It fixed the issue. Thank you! Maybe you could also suggest some good tutorials about widgets and best practices in general? Thank you very much!

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [September 11, 2023, 2:46pm UTC](https://forums.unrealengine.com/t/widget-create-blueprint-runtime-error/1290357/13 "2023-09-11T14:46:32Z")

</div>

> [@NosferatuVampir](#):
>
> Thank you! Maybe you could also suggest some good tutorials about widgets and best practices in general?

You’d need to be more specific. There’s too much stuff out there! The two things that come to mind:

- employ an Event Driven approach as often as you can - the 3rd example [here](https://docs.unrealengine.com/4.27/en-US/InteractiveExperiences/UMG/HowTo/EventBasedUI/).
- this very message that did not get enough recognition but should be framed over the bed of every UI dev and tutorial maker:

> [@UnrealEverything](#):
>
> Your UI should ideally not contain any game logic.

---

<div class="post-metadata">

**Author:** ![system](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/1/3/713c9d3f58553f0de89543d76a8a3a2779dc9fa4.png) [@system](https://forums.unrealengine.com/u/system)\
**Post date:** [October 11, 2023, 2:47pm UTC](https://forums.unrealengine.com/t/widget-create-blueprint-runtime-error/1290357/14 "2023-10-11T14:47:08Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
