# UWidget::IsHovered causes a crash

**URL:** <https://forums.unrealengine.com/t/uwidget-ishovered-causes-a-crash/446181>\
**Category:** C++\
**Tags:** nullptr, unreal-engine, crash, UE4, question, CPP\
**Created:** [March 28, 2019, 5:01pm UTC](https://forums.unrealengine.com/t/uwidget-ishovered-causes-a-crash/446181 "2019-03-28T17:01:29Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_24db18e6](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_24db18e6](https://forums.unrealengine.com/u/anonymous_user_24db18e6)\
**Post date:** [March 28, 2019, 5:01pm UTC](https://forums.unrealengine.com/t/uwidget-ishovered-causes-a-crash/446181/1 "2019-03-28T17:01:29Z")

</div>

We have a custom `UWidget` class that represents an item in a menu. There are two places where we call `IsHovered` on that class and they both crash seemingly randomly.

In the `UUserWidget` subclass that contains the menu items we iterate over them to see which one is selected using this code:

```
UMenuItem* NewSelection = nullptr;
for (UMenuItem* MenuItem : Children)
{
	if (MenuItem->IsHovered())
	{
		NewSelection = MenuItem;
		break;
	}
}

```

Randomly it crashes on the `MenuItem->IsHovered()` line with an error that says `MenuItem is nullptr` but when it breaks we can inspect it and it’s not a `nullptr` and everything in the callstack looks good.

The other place that it crashes is in the `UMenuItem` class itself. In the tick method we just have some code that checks whether it’s hovered and updates the highlight state of the widget.

```
Hovered = IsHovered();
UpdateHighlight();

```

When the crash happens here it says `this-> is nullptr` but again we can inspect when it breaks and see that this is not the case. We can even step up the callstack and verify that the list that’s holding the menu items looks good.

Has anyone seen a crash like this before?

---

<div class="post-metadata">

**Author:** ![emperor\_katax](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/emperor_katax/32/1070178_2.png) [@emperor\_katax](https://forums.unrealengine.com/u/emperor_katax)\
**Post date:** [March 29, 2019, 4:52am UTC](https://forums.unrealengine.com/t/uwidget-ishovered-causes-a-crash/446181/2 "2019-03-29T04:52:47Z")

</div>

…. you may check if your `MenuItem` is not a `null` value. Mostly sudden crashes caused by access null objects, in your case, it may try to execute `->IsHovered()` and it end up with `null->IsHovered()` and then , crashed. …

try:

```
if (MenuItem != nullptr) {
   if (MenuItem->IsHovered())
     {
         NewSelection = MenuItem;
         break;
     }
}
```
