# How to see if WidgetClass has been set?

**URL:** <https://forums.unrealengine.com/t/how-to-see-if-widgetclass-has-been-set/1200864>\
**Category:** C++\
**Tags:** unreal-engine, question\
**Created:** [June 16, 2023, 4:13am UTC](https://forums.unrealengine.com/t/how-to-see-if-widgetclass-has-been-set/1200864 "2023-06-16T04:13:15Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![ShadowSprite123](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ShadowSprite123](https://forums.unrealengine.com/u/ShadowSprite123)\
**Post date:** [June 16, 2023, 4:13am UTC](https://forums.unrealengine.com/t/how-to-see-if-widgetclass-has-been-set/1200864/1 "2023-06-16T04:13:15Z")

</div>

I wanna see if a the widget class on a component has been set and if so set it to nullptr. Currently I’m using:

```auto
if (LockedOnWidget->GetWidgetClass() != nullptr)
	{
		LockedOnWidget->SetWidgetClass(nullptr);
	}

```

And it works fine but occasionally it crashes and I don’t know why. Any reasons?  
Thanks in advance.🙂

---

<div class="post-metadata">

**Author:** ![NikitaAksenov](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@NikitaAksenov](https://forums.unrealengine.com/u/NikitaAksenov)\
**Post date:** [June 16, 2023, 8:04am UTC](https://forums.unrealengine.com/t/how-to-see-if-widgetclass-has-been-set/1200864/2 "2023-06-16T08:04:51Z")

</div>

Hi!

Can you, please, provide message that appeared with the crash?

---

<div class="post-metadata">

**Author:** ![ShadowSprite123](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ShadowSprite123](https://forums.unrealengine.com/u/ShadowSprite123)\
**Post date:** [June 16, 2023, 10:15am UTC](https://forums.unrealengine.com/t/how-to-see-if-widgetclass-has-been-set/1200864/3 "2023-06-16T10:15:24Z")

</div>

[https://d3kjluh73b9h9o.cloudfront.net/original/4X/8/3/e/83e2e279101f9b22bc2995fccdc93f4c47d5cc4b.mp4](https://d3kjluh73b9h9o.cloudfront.net/original/4X/8/3/e/83e2e279101f9b22bc2995fccdc93f4c47d5cc4b.mp4)
  
Unhandled Exception: EXCEPTION\_ACCESS\_VIOLATION reading address 0x00000000000004b0

UnrealEditor\_Project\_TBU!ATargetDummy::EnableWidget() [C:\Users\silen\Documents\Projects\UE\Games\Project\_TBU\Source\Project\_TBU\TargetDummy.cpp:67]  
UnrealEditor\_Project\_TBU!AMainCharacterTesting::TargetEnemy() [C:\Users\silen\Documents\Projects\UE\Games\Project\_TBU\Source\Project\_TBU\MainCharacterTesting.cpp:193]  
UnrealEditor\_Project\_TBU!TBaseUObjectMethodDelegateInstance\<0,AMainCharacterTesting,void \_\_cdecl(void),FDefaultDelegateUserPolicy\>::Execute() [C:\Program Files\Epic Games\UE\_5.2\Engine\Source\Runtime\Core\Public\Delegates\DelegateInstancesImpl.h:535]  
UnrealEditor\_Engine  
UnrealEditor\_Engine  
UnrealEditor\_EnhancedInput  
UnrealEditor\_Engine  
UnrealEditor\_Engine  
UnrealEditor\_Engine  
UnrealEditor\_Engine  
UnrealEditor\_Engine  
UnrealEditor\_Engine  
UnrealEditor\_Engine  
UnrealEditor\_Core  
UnrealEditor\_Core  
UnrealEditor\_Core  
UnrealEditor\_Engine  
UnrealEditor\_Engine  
UnrealEditor\_Engine  
UnrealEditor\_Engine  
UnrealEditor\_UnrealEd  
UnrealEditor\_UnrealEd  
UnrealEditor  
UnrealEditor  
UnrealEditor  
UnrealEditor  
UnrealEditor  
UnrealEditor  
kernel32  
ntdll

---

<div class="post-metadata">

**Author:** ![NikitaAksenov](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@NikitaAksenov](https://forums.unrealengine.com/u/NikitaAksenov)\
**Post date:** [June 16, 2023, 10:58am UTC](https://forums.unrealengine.com/t/how-to-see-if-widgetclass-has-been-set/1200864/4 "2023-06-16T10:58:14Z")

</div>

Thanks for the vid!

Can you, please, show code from TargetDummy.cpp on row 67?

---

<div class="post-metadata">

**Author:** ![ShadowSprite123](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ShadowSprite123](https://forums.unrealengine.com/u/ShadowSprite123)\
**Post date:** [June 16, 2023, 11:13am UTC](https://forums.unrealengine.com/t/how-to-see-if-widgetclass-has-been-set/1200864/5 "2023-06-16T11:13:28Z")

</div>

Oh it’s in the video both lines at where it crashes.

---

<div class="post-metadata">

**Author:** ![NikitaAksenov](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@NikitaAksenov](https://forums.unrealengine.com/u/NikitaAksenov)\
**Post date:** [June 16, 2023, 11:17am UTC](https://forums.unrealengine.com/t/how-to-see-if-widgetclass-has-been-set/1200864/6 "2023-06-16T11:17:42Z")

</div>

Oh, you’re right, thanks.

Try adding this code at the beginning of the ATargetDummy::EnableWidget()

```auto
if (LockedOnWidget == nullptr)
{
     return;
}

```

---

<div class="post-metadata">

**Author:** ![ShadowSprite123](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ShadowSprite123](https://forums.unrealengine.com/u/ShadowSprite123)\
**Post date:** [June 17, 2023, 3:29am UTC](https://forums.unrealengine.com/t/how-to-see-if-widgetclass-has-been-set/1200864/7 "2023-06-17T03:29:00Z")

</div>

Didn’t work but I think I found the cause. It’s something to do with the Overlap events. I’ll keep u up to date.

---

<div class="post-metadata">

**Author:** ![ShadowSprite123](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ShadowSprite123](https://forums.unrealengine.com/u/ShadowSprite123)\
**Post date:** [June 17, 2023, 3:29am UTC](https://forums.unrealengine.com/t/how-to-see-if-widgetclass-has-been-set/1200864/8 "2023-06-17T03:29:14Z")

</div>

Ty for helping tho.🙂

---

<div class="post-metadata">

**Author:** ![Ivan3z](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Ivan3z](https://forums.unrealengine.com/u/Ivan3z)\
**Post date:** [June 17, 2023, 4:07am UTC](https://forums.unrealengine.com/t/how-to-see-if-widgetclass-has-been-set/1200864/9 "2023-06-17T04:07:26Z")

</div>

Use IsValid() function intead nullptr olso… nullptr is not enough for UObject pointers
