# \[C++\]how to get a umg component reference from an umg i created in c++ and extended in bp

**URL:** <https://forums.unrealengine.com/t/c-how-to-get-a-umg-component-reference-from-an-umg-i-created-in-c-and-extended-in-bp/487683>\
**Category:** UI\
**Tags:** unreal-engine, Blueprint, question, CPP, UMG, actor-class\
**Created:** [August 19, 2021, 8:58pm UTC](https://forums.unrealengine.com/t/c-how-to-get-a-umg-component-reference-from-an-umg-i-created-in-c-and-extended-in-bp/487683 "2021-08-19T20:58:47Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![R4v3n77](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@R4v3n77](https://forums.unrealengine.com/u/R4v3n77)\
**Post date:** [August 19, 2021, 8:58pm UTC](https://forums.unrealengine.com/t/c-how-to-get-a-umg-component-reference-from-an-umg-i-created-in-c-and-extended-in-bp/487683/1 "2021-08-19T20:58:47Z")

</div>

Hi, im trying to make a 3d scrollbox which i will fill on c++ during runtime.

i created a umg in c++ named “TabletScreen” with

```
UPROPERTY(meta = (BindWidget))
	class UScrollBox* mScrollBox;

UPROPERTY(meta = (BindWidget))
	class UWrapBox* mWrapBox;

```

and give this class also a getWrapBox()

```
UWrapBox* UPokerTabletScreen::getWrapBox()
{
	return mWrapBox;
}

```

then extended this class with a blueprint, and attached a wrapbox and scrollbox with the same name as my variabile in the c++ class.

![346752-screen.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/2/f/72ff745425db13d14b5a56093ae48e34ebc64cb7.jpeg)

after this i created an actor named “tablet” in c++ with a widgetcomponent, i placed this actor in the world and put my blueprint\_tabletscreen class as a variable.

![346753-screen.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/1/7/3/1735c118716f49323eacf3aa0dade7b9232c6ad9.jpeg)

after this i proceed to get first a reference to my tabletscreen class, then use the method getWrapBox to attach some textboxes but i crashed when i use getWrapBox

```
	UPokerTabletScreen* pk = (UPokerTabletScreen*)mTabletWidgetComponent->GetUserWidgetObject();
	UWrapBox* wrapBox = pk->getWrapBox();

```

with this error

Unhandled Exception: EXCEPTION\_ACCESS\_VIOLATION reading address 0x0000000000000400

UE4Editor\_Poker3d\_1042!UPokerTabletScreen::getWrapBox() [C:\Users\nerfl\Documents\Unreal Projects\Poker3d\Source\Poker3d\PokerTabletScreen.cpp:13]

surely im doing something wrong but i cant really figure it, my objective is to create a tablet or something like that with a scrollbox that im gonna fill dynamically

---

<div class="post-metadata">

**Author:** ![Kehel18](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Kehel18](https://forums.unrealengine.com/u/Kehel18)\
**Post date:** [August 20, 2021, 3:06pm UTC](https://forums.unrealengine.com/t/c-how-to-get-a-umg-component-reference-from-an-umg-i-created-in-c-and-extended-in-bp/487683/2 "2021-08-20T15:06:45Z")

</div>

Hello! You can just use code like this to stay safe from nullptr exception

```
     if (UPokerTabletScreen* pk = Cast<UPokerTabletScreen>(mTabletWidgetComponent->GetUserWidgetObject())){
     UWrapBox* wrapBox = pk->getWrapBox();
}

```

One more thing - do you check that WidgetComponent already has created its Widget at the time you try to call this?

---

<div class="post-metadata">

**Author:** ![R4v3n77](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@R4v3n77](https://forums.unrealengine.com/u/R4v3n77)\
**Post date:** [August 20, 2021, 5:38pm UTC](https://forums.unrealengine.com/t/c-how-to-get-a-umg-component-reference-from-an-umg-i-created-in-c-and-extended-in-bp/487683/3 "2021-08-20T17:38:58Z")

</div>

Hi! First of all thanks for answering. I will try when I’m at home.

I placed that actor with the widgetcomponent in the world with the editor so if im not mistaken it’s should already be fine right?

---

<div class="post-metadata">

**Author:** ![Kehel18](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Kehel18](https://forums.unrealengine.com/u/Kehel18)\
**Post date:** [August 23, 2021, 10:07am UTC](https://forums.unrealengine.com/t/c-how-to-get-a-umg-component-reference-from-an-umg-i-created-in-c-and-extended-in-bp/487683/4 "2021-08-23T10:07:09Z")

</div>

In most cases yes, but there can be issues and config when it is not fine. So you better check that anyway…
