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?
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?
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.
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 );
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 !