# How to set the widget class to none in c++

**URL:** <https://forums.unrealengine.com/t/how-to-set-the-widget-class-to-none-in-c/1190995>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine, question\
**Created:** [June 6, 2023, 7:21pm UTC](https://forums.unrealengine.com/t/how-to-set-the-widget-class-to-none-in-c/1190995 "2023-06-06T19:21:27Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![3dRaven](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/3draven/32/906552_2.png) [@3dRaven](https://forums.unrealengine.com/u/3dRaven)\
**Post date:** [June 6, 2023, 10:20pm UTC](https://forums.unrealengine.com/t/how-to-set-the-widget-class-to-none-in-c/1190995/4 "2023-06-06T22:20:44Z")

</div>

[WidgetC.zip](https://forums.unrealengine.com/uploads/short-url/yKHeaoPZuAxhDsdU3HbZr2oEyOq.zip) (44.4 KB)  
1 key turns the widget component on and off via c++

The crucial part:

```auto

void AMyCharacter::SetWidget(TSubclassOf<class UUserWidget> passedWidget) {
	
	if (passedWidget != nullptr) {
		UUserWidget* widget = CreateWidget<UUserWidget>(GetWorld(), passedWidget);
		widgetComponent->SetWidget(widget);
	} else {
		widgetComponent->SetWidget(nullptr);
	}
	
}

``
```

---

_[View the full topic](https://forums.unrealengine.com/t/how-to-set-the-widget-class-to-none-in-c/1190995)._
