# C++ Widget does not show anything on screen

**URL:** <https://forums.unrealengine.com/t/c-widget-does-not-show-anything-on-screen/453617>\
**Category:** UI\
**Tags:** unreal-engine, Widget, question, Blueprint, CPP\
**Created:** [August 9, 2019, 9:53am UTC](https://forums.unrealengine.com/t/c-widget-does-not-show-anything-on-screen/453617 "2019-08-09T09:53:27Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![Repin\_Design](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/repin_design/32/598391_2.png) [@Repin\_Design](https://forums.unrealengine.com/u/Repin_Design)\
**Post date:** [April 30, 2023, 10:16pm UTC](https://forums.unrealengine.com/t/c-widget-does-not-show-anything-on-screen/453617/3 "2023-04-30T22:16:21Z")

</div>

First of all u need to create root widget with Init function. It wont work other way, if u need visual part of widget to be visible in Widget BP Editor u need to use NativePreConstruct(), then u can see the changes after every compile, NativeConstruct() arent working in the editor.

```auto
-h
virtual bool Initialize() override;

-cpp

bool UWIDGET::Initialize() {

    bool RESPONSE = Super::Initialize();

    if (!HasAnyFlags(RF_ClassDefaultObject)) {
        BODY = WidgetTree->ConstructWidget<USizeBox>();
        WidgetTree->RootWidget = BODY;
    }

    return RESPONSE;

}

```

and don’t try to add other widgets to rootwidget in Initialize function , it will crash the editor, setup root widget in Init and add other stuff to it in NativeConstruct() or NativePreConstruct(), also u’ll probably wont see all ur stuff in widget tree in bp editor, just result of compilation in preview window, u need to register those elements somehow to see them in BP editor widgetree, but i don’t know how.

here’s the way u add slots

```auto
SPACE = WidgetTree->ConstructWidget<UCanvasPanel>();
auto BODY_SLOT = BODY->AddChild(SPACE);

```

no need to Cast like u did.

Peace.

---

_[View the full topic](https://forums.unrealengine.com/t/c-widget-does-not-show-anything-on-screen/453617)._
