# Crash after creating widget on death

**URL:** <https://forums.unrealengine.com/t/crash-after-creating-widget-on-death/450561>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine\
**Created:** [June 12, 2019, 3:14pm UTC](https://forums.unrealengine.com/t/crash-after-creating-widget-on-death/450561 "2019-06-12T15:14:10Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Strikeless](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Strikeless](https://forums.unrealengine.com/u/Strikeless)\
**Post date:** [June 12, 2019, 3:14pm UTC](https://forums.unrealengine.com/t/crash-after-creating-widget-on-death/450561/1 "2019-06-12T15:14:10Z")

</div>

Hi, I’ve been trying to create a widget after destroying my player and it doesn’t seem to be working.  
Very confused here, hoping for some help.

`
```
UGameplayStatics::SpawnEmitterAtLocation(GetWorld(), playerDeathExplosion, player->GetActorLocation()); // spawn death explosion

player->Destroy(); // kill player

APlayerController* controller = UGameplayStatics::GetPlayerController(GetWorld(), 0);

 // crash happens here

if (URespawnCPP* RespawnUserWidget = CreateWidget<URespawnCPP>(controller, RespawnWidget.LoadSynchronous()))
{
    controller->SetInputMode(FInputModeUIOnly());
    controller->bShowMouseCursor = true;
    RespawnUserWidget->AddToViewport();
}

```
`

error:  
[https://hasteb.in/axupilub.php](https://hasteb.in/axupilub.php)

---

<div class="post-metadata">

**Author:** ![Firefly74](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Firefly74](https://forums.unrealengine.com/u/Firefly74)\
**Post date:** [June 12, 2019, 3:24pm UTC](https://forums.unrealengine.com/t/crash-after-creating-widget-on-death/450561/2 "2019-06-12T15:24:41Z")

</div>

Seemed to be linked to you widget, could you try make a simple UMG one ?  
Also, to be sure you are not destroying player character when he die, check if pointer is valid and not pending to kill

---

<div class="post-metadata">

**Author:** ![Strikeless](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Strikeless](https://forums.unrealengine.com/u/Strikeless)\
**Post date:** [June 12, 2019, 3:33pm UTC](https://forums.unrealengine.com/t/crash-after-creating-widget-on-death/450561/3 "2019-06-12T15:33:03Z")

</div>

Same crash even with a simple widget calling ‘UUserWidget’ instead of my custom class.

---

<div class="post-metadata">

**Author:** ![Firefly74](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Firefly74](https://forums.unrealengine.com/u/Firefly74)\
**Post date:** [June 12, 2019, 3:36pm UTC](https://forums.unrealengine.com/t/crash-after-creating-widget-on-death/450561/4 "2019-06-12T15:36:49Z")

</div>

What is strange is that call stack doesn’t show you code, but something like next tick

---

<div class="post-metadata">

**Author:** ![Strikeless](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Strikeless](https://forums.unrealengine.com/u/Strikeless)\
**Post date:** [June 12, 2019, 3:37pm UTC](https://forums.unrealengine.com/t/crash-after-creating-widget-on-death/450561/5 "2019-06-12T15:37:18Z")

</div>

I don’t understand it either. Possible bug?

---

<div class="post-metadata">

**Author:** ![MrMcKvarz](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@MrMcKvarz](https://forums.unrealengine.com/u/MrMcKvarz)\
**Post date:** [June 12, 2019, 3:46pm UTC](https://forums.unrealengine.com/t/crash-after-creating-widget-on-death/450561/6 "2019-06-12T15:46:47Z")

</div>

Can you load widget first and check whether it had been loaded before passing it to CreateWidget?

---

<div class="post-metadata">

**Author:** ![Strikeless](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Strikeless](https://forums.unrealengine.com/u/Strikeless)\
**Post date:** [June 12, 2019, 3:49pm UTC](https://forums.unrealengine.com/t/crash-after-creating-widget-on-death/450561/7 "2019-06-12T15:49:34Z")

</div>

I can confirm it does load.

---

<div class="post-metadata">

**Author:** ![Firefly74](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Firefly74](https://forums.unrealengine.com/u/Firefly74)\
**Post date:** [June 12, 2019, 3:51pm UTC](https://forums.unrealengine.com/t/crash-after-creating-widget-on-death/450561/8 "2019-06-12T15:51:47Z")

</div>

Probably not

try these things :  
surround your method like this to disable compilation optimisation for that part of code ( easier to debug ) :  
also load the class on a separated part, just to be sure

```
#pragma optimize("", off)
    void myClass::MyMethod()
    {
        UGameplayStatics::SpawnEmitterAtLocation(GetWorld(), playerDeathExplosion, player->GetActorLocation()); // spawn death explosion
     
        player->Destroy(); // kill player
     
        APlayerController* controller = UGameplayStatics::GetPlayerController(GetWorld(), 0);
        auto widgetClass = RespawnWidget.LoadSynchronous()
        if(controller && widgetClass )
        {
            if (URespawnCPP* RespawnUserWidget = CreateWidget<URespawnCPP>(controller, widgetClass ))
            {
                controller->SetInputMode(FInputModeUIOnly());
                controller->bShowMouseCursor = true;
                RespawnUserWidget->AddToViewport();
            }
        }
    }
#pragma optimize("", on)
```

---

<div class="post-metadata">

**Author:** ![Strikeless](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Strikeless](https://forums.unrealengine.com/u/Strikeless)\
**Post date:** [June 12, 2019, 3:56pm UTC](https://forums.unrealengine.com/t/crash-after-creating-widget-on-death/450561/9 "2019-06-12T15:56:45Z")

</div>

I still get the same exact error…

---

<div class="post-metadata">

**Author:** ![Firefly74](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Firefly74](https://forums.unrealengine.com/u/Firefly74)\
**Post date:** [June 12, 2019, 3:57pm UTC](https://forums.unrealengine.com/t/crash-after-creating-widget-on-death/450561/10 "2019-06-12T15:57:41Z")

</div>

can you get the crash with visual studio attached ? with new code i shared, what line does the crash ?

---

<div class="post-metadata">

**Author:** ![Strikeless](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Strikeless](https://forums.unrealengine.com/u/Strikeless)\
**Post date:** [June 12, 2019, 3:59pm UTC](https://forums.unrealengine.com/t/crash-after-creating-widget-on-death/450561/11 "2019-06-12T15:59:40Z")

</div>

![279584-untitled.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/b/3/2/b324697cf601f53d32dca057827306d814495aac.png)

---

<div class="post-metadata">

**Author:** ![Firefly74](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Firefly74](https://forums.unrealengine.com/u/Firefly74)\
**Post date:** [June 12, 2019, 4:13pm UTC](https://forums.unrealengine.com/t/crash-after-creating-widget-on-death/450561/12 "2019-06-12T16:13:36Z")

</div>

pretty sure i already encountered this one but can recall what was the problem …

instead of the controller can you pass “GetWorld()” in CreateWidget ?

also if it still crash, can you comment the "add to veiwport ?  
if still crash, uncomment that and add “RespawnUserWidget-\>AddToRoot();” before the addtoViewport

---

<div class="post-metadata">

**Author:** ![Strikeless](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Strikeless](https://forums.unrealengine.com/u/Strikeless)\
**Post date:** [June 12, 2019, 4:20pm UTC](https://forums.unrealengine.com/t/crash-after-creating-widget-on-death/450561/13 "2019-06-12T16:20:39Z")

</div>

doesn’t crash when I comment AddToViewport() but when I add the AddToRoot() + AddToViewport() it crashes.

---

<div class="post-metadata">

**Author:** ![Firefly74](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Firefly74](https://forums.unrealengine.com/u/Firefly74)\
**Post date:** [June 12, 2019, 5:22pm UTC](https://forums.unrealengine.com/t/crash-after-creating-widget-on-death/450561/14 "2019-06-12T17:22:25Z")

</div>

Then i would need the code of your “URespawnCPP” class, last thing i can see is you using some code in there causing this ( maybe an image you load programatically ? )

---

<div class="post-metadata">

**Author:** ![Strikeless](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Strikeless](https://forums.unrealengine.com/u/Strikeless)\
**Post date:** [June 12, 2019, 5:23pm UTC](https://forums.unrealengine.com/t/crash-after-creating-widget-on-death/450561/15 "2019-06-12T17:23:18Z")

</div>

I mean I loaded a UUserWidget widget non related to my URespawnCPP class and it also crashed… not sure how it can be much different.

---

<div class="post-metadata">

**Author:** ![Firefly74](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Firefly74](https://forums.unrealengine.com/u/Firefly74)\
**Post date:** [June 13, 2019, 7:08am UTC](https://forums.unrealengine.com/t/crash-after-creating-widget-on-death/450561/16 "2019-06-13T07:08:03Z")

</div>

then it’s related of when you use it, try to spawn it ingame with same code ?  
You said when player die, but what happen if you don’t spawn it ? you go back to main menu or just stay there ?

You do have engine pdb and sources downloaded right ? could you browse the stack trace to find more info on what going on ?

---

<div class="post-metadata">

**Author:** ![Strikeless](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Strikeless](https://forums.unrealengine.com/u/Strikeless)\
**Post date:** [June 13, 2019, 6:08pm UTC](https://forums.unrealengine.com/t/crash-after-creating-widget-on-death/450561/17 "2019-06-13T18:08:24Z")

</div>

If I don’t spawn the widget?  
it just ends up leaving me there.

I don’t have the engine source because it’s way too big, I still have no idea of what’s going on.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_e317d48f](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_e317d48f](https://forums.unrealengine.com/u/anonymous_user_e317d48f)\
**Post date:** [June 13, 2019, 8:16pm UTC](https://forums.unrealengine.com/t/crash-after-creating-widget-on-death/450561/18 "2019-06-13T20:16:28Z")

</div>

Using Blueprints, if a widget was created inside the CharacterBP and the character is then destroyed - an error will occur.

The widget would have to be created elsewhere, in an asset that does not get destroyed.

I’m not a c++ guy, but I hope this may shed some light on what may be happening.

Where is the widget being created ??

---

<div class="post-metadata">

**Author:** ![Strikeless](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Strikeless](https://forums.unrealengine.com/u/Strikeless)\
**Post date:** [June 13, 2019, 8:46pm UTC](https://forums.unrealengine.com/t/crash-after-creating-widget-on-death/450561/19 "2019-06-13T20:46:48Z")

</div>

In the character, so I can probably try somewhere else then.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_e317d48f](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_e317d48f](https://forums.unrealengine.com/u/anonymous_user_e317d48f)\
**Post date:** [June 13, 2019, 11:44pm UTC](https://forums.unrealengine.com/t/crash-after-creating-widget-on-death/450561/20 "2019-06-13T23:44:58Z")

</div>

yea, try creating the widget in the Level BP (or perhaps your player controller), and see if the same error occurs upon the character’s death. good luck

[Next page](https://forums.unrealengine.com/t/crash-after-creating-widget-on-death/450561.md?page=2)
