# Access slate widget through shared pointer

**URL:** <https://forums.unrealengine.com/t/access-slate-widget-through-shared-pointer/471977>\
**Category:** UI\
**Tags:** unreal-engine, slate, question, CPP\
**Created:** [September 26, 2020, 11:26am UTC](https://forums.unrealengine.com/t/access-slate-widget-through-shared-pointer/471977 "2020-09-26T11:26:47Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Althaen](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Althaen](https://forums.unrealengine.com/u/Althaen)\
**Post date:** [September 26, 2020, 11:26am UTC](https://forums.unrealengine.com/t/access-slate-widget-through-shared-pointer/471977/1 "2020-09-26T11:26:47Z")

</div>

I have created some Slate widgets with shared pointers for child widgets that I need to update information on later. I can’t access them directly and I apparently have to convert them to shared references? I’m trying to update the text block of one of the widgets. I also get an error message about thread safety, will I need to mark the pointers as thread safe?

---

<div class="post-metadata">

**Author:** ![irajsb](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/irajsb/32/740687_2.png) [@irajsb](https://forums.unrealengine.com/u/irajsb)\
**Post date:** [September 26, 2020, 5:35pm UTC](https://forums.unrealengine.com/t/access-slate-widget-through-shared-pointer/471977/2 "2020-09-26T17:35:10Z")

</div>

[Here is my UMG code if you need an example !](https://github.com/irajsb/UE4_TitanUMG)

---

<div class="post-metadata">

**Author:** ![Althaen](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Althaen](https://forums.unrealengine.com/u/Althaen)\
**Post date:** [September 26, 2020, 10:58pm UTC](https://forums.unrealengine.com/t/access-slate-widget-through-shared-pointer/471977/3 "2020-09-26T22:58:23Z")

</div>

So do you need to create a new widget of the same type and assign it to the shared pointer and then convert to a shared ref? I am using the Slate Construct() to add and assign child widgets, do I need to do both?

---

<div class="post-metadata">

**Author:** ![irajsb](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/irajsb/32/740687_2.png) [@irajsb](https://forums.unrealengine.com/u/irajsb)\
**Post date:** [September 27, 2020, 4:23am UTC](https://forums.unrealengine.com/t/access-slate-widget-through-shared-pointer/471977/4 "2020-09-27T04:23:12Z")

</div>

My code is how Epic does it(I Explored source files ) so I guess my code is pretty standard .I also need to know what you are trying to achieve because answer maybe diffrent.UE4 Adds childs using slots by default !

---

<div class="post-metadata">

**Author:** ![Althaen](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Althaen](https://forums.unrealengine.com/u/Althaen)\
**Post date:** [September 27, 2020, 4:52am UTC](https://forums.unrealengine.com/t/access-slate-widget-through-shared-pointer/471977/5 "2020-09-27T04:52:46Z")

</div>

I have a widget that holds other widgets like inventory, chat etc. and I use SAssignNew in the construct functions of these widgets. I am trying to use the SetText function on a text block but running it does nothing.

---

<div class="post-metadata">

**Author:** ![irajsb](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/irajsb/32/740687_2.png) [@irajsb](https://forums.unrealengine.com/u/irajsb)\
**Post date:** [September 27, 2020, 5:18am UTC](https://forums.unrealengine.com/t/access-slate-widget-through-shared-pointer/471977/6 "2020-09-27T05:18:21Z")

</div>

here is the code that should be called(not exactly like this but similar) to properly initialize a text block (ignore the if condition,There are two ways of init a text block one is inside if and one is inside the else try both to see what works! )

```
if (bWrapWithInvalidationPanel && !IsDesignTime())
 	{
 		TSharedPtr<SWidget> RetWidget = SNew(SInvalidationPanel)
 		[
 			SAssignNew(MyTextBlock, STextBlock)
			.SimpleTextMode(bSimpleTextMode)
 		];
 		return RetWidget.ToSharedRef();
 	}
 	else
	{
		MyTextBlock =
			SNew(STextBlock)
			.SimpleTextMode(bSimpleTextMode); 

```

you may also need to init font and style like:

```
TAttribute<FText> TextBinding = GetDisplayText();
TAttribute<FSlateColor> ColorAndOpacityBinding = PROPERTY_BINDING(FSlateColor, ColorAndOpacity);
TAttribute<FLinearColor> ShadowColorAndOpacityBinding = PROPERTY_BINDING(FLinearColor, ShadowColorAndOpacity);

if ( MyTextBlock.IsValid() )
{
	MyTextBlock->SetText( TextBinding );
	MyTextBlock->SetFont( Font );
	MyTextBlock->SetStrikeBrush( &StrikeBrush );
	MyTextBlock->SetColorAndOpacity( ColorAndOpacityBinding );
	MyTextBlock->SetShadowOffset( ShadowOffset );
	MyTextBlock->SetShadowColorAndOpacity( ShadowColorAndOpacityBinding );
	MyTextBlock->SetMinDesiredWidth( MinDesiredWidth );
```
