# Manipulating Slate content during and after Construct()

**URL:** <https://forums.unrealengine.com/t/manipulating-slate-content-during-and-after-construct/279697>\
**Category:** UI\
**Tags:** reset, delete, unreal-engine, slate, question\
**Created:** [April 5, 2014, 8:35pm UTC](https://forums.unrealengine.com/t/manipulating-slate-content-during-and-after-construct/279697 "2014-04-05T20:35:36Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![StrangerGwenn](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/strangergwenn/32/983202_2.png) [@StrangerGwenn](https://forums.unrealengine.com/u/StrangerGwenn)\
**Post date:** [April 5, 2014, 8:35pm UTC](https://forums.unrealengine.com/t/manipulating-slate-content-during-and-after-construct/279697/1 "2014-04-05T20:35:36Z")

</div>

Hi,

I am getting started with the Slate framework. I have created various UI components, set up style, callbacks, etc. Now I want to go a little further and I am stuck on two things.

The first question is about updating FSlateBrushes. I have a big menu with a few of those, I want to hide/show the menu. That is easy but I also want to change the brushes each time I show the menu. Of course, I could simply destroy and Construct the menu again each time but this is going to happen every few seconds, I think there is a better way. How can I change FSlateBrushes after they’ve been constructed ?

More generally, how can I re-initialize or delete content that was declared with SNew ? Should I use SEssignNew then Reset() the reference ?

The second question is a bit more trivial. What would be the syntax for using SNew in a for loop inside ChildSlot[], or even deeper into the Construct() (e.g. in a box slot, etc) ?

Thanks !

---

<div class="post-metadata">

**Author:** ![Jamie\_Dale](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/jamie_dale/32/1165413_2.png) [@Jamie\_Dale](https://forums.unrealengine.com/u/Jamie_Dale)\
**Post date:** [April 5, 2014, 8:40pm UTC](https://forums.unrealengine.com/t/manipulating-slate-content-during-and-after-construct/279697/2 "2014-04-05T20:40:37Z")

</div>

Updating a Slate brush would generally be done via a delegate. Slate widgets can take arguments in the form of SLATE\_ARGUMENT, or SLATE\_ATTRIBUTE; an attribute can be optionally bound to a delegate to allow you to dynamically change the value at runtime, eg)

```
SNew(SImage).Image(this, &MyWidget::GetMyBrush)

```

If you want to populate a slot via a for loop, you can use SAssignNew to assign the thing with the slots (eg, SHorizontalBox) to a variable, and then use AddSlot(…) on that variable rather than using the Slate declarative syntax directly.

---

<div class="post-metadata">

**Author:** ![StrangerGwenn](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/strangergwenn/32/983202_2.png) [@StrangerGwenn](https://forums.unrealengine.com/u/StrangerGwenn)\
**Post date:** [April 5, 2014, 8:57pm UTC](https://forums.unrealengine.com/t/manipulating-slate-content-during-and-after-construct/279697/3 "2014-04-05T20:57:47Z")

</div>

You really are the lifesaver today !

Okay so the loop thing is good, I did like in SShooterScoreboardWidget that does it, for anyone else reading. Works very well and the code is clean.

Now for the delegate thing, does this mean that each Construct call will simply load the resource from a user callback ? Can I use Slate parameters with this (that would be the icing on the cake) ?

---

<div class="post-metadata">

**Author:** ![Jamie\_Dale](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/jamie_dale/32/1165413_2.png) [@Jamie\_Dale](https://forums.unrealengine.com/u/Jamie_Dale)\
**Post date:** [April 5, 2014, 9:05pm UTC](https://forums.unrealengine.com/t/manipulating-slate-content-during-and-after-construct/279697/4 "2014-04-05T21:05:55Z")

</div>

Assuming I understand your question correctly, yes, and yes.

If you have a Slate parameter which is from a SLATE\_ATTRIBUTE with the same signature as the widget you ultimately give it to, then that can be passed through as is via the InArgs for your widget.

If your widget is custom enough that it doesn’t take this data via a Slate parameter, then you can just give it a callback local to that widget.

Ultimately you should end up with a delegate somewhere returning a const FSlateBrush\* returned from a Slate style set.

```
void SMyWidget::Construct(const FArguments& InArgs)
{
    ChildContent
    [
        SNew(SImage).Image(this, &SMyWidget::GetMyBrush)
    ];
}

const FSlateBrush* SMyWidget::GetMyBrush() const
{
    return (MySuperStateThatNeedsADifferentBrush)
        ? FMySlateStyle::Get().GetBrush("MySuperBrush")
        : FMySlateStyle::Get().GetBrush("MyNormalBrush");

}

```

---

<div class="post-metadata">

**Author:** ![StrangerGwenn](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/strangergwenn/32/983202_2.png) [@StrangerGwenn](https://forums.unrealengine.com/u/StrangerGwenn)\
**Post date:** [April 5, 2014, 9:11pm UTC](https://forums.unrealengine.com/t/manipulating-slate-content-during-and-after-construct/279697/5 "2014-04-05T21:11:42Z")

</div>

Okay, I wanted to directly pass parameters to the delegate but this will do very well too since I’m going to have a few different callbacks.

Thank you very much for your help.

---

<div class="post-metadata">

**Author:** ![Jamie\_Dale](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/jamie_dale/32/1165413_2.png) [@Jamie\_Dale](https://forums.unrealengine.com/u/Jamie_Dale)\
**Post date:** [April 5, 2014, 9:14pm UTC](https://forums.unrealengine.com/t/manipulating-slate-content-during-and-after-construct/279697/6 "2014-04-05T21:14:56Z")

</div>

Ah, yes, you can totally do that via binding 🙂

Assuming you have a variable available to Construct called RandomVarToBind of type TSharedPtr of FMyType (this can be any type, but also remember it’s bound by value).

```
void SMyWidget::Construct(const FArguments& InArgs)
{
    TSharedPtr<FMyType> RandomVarToBind = /* ... */

    ChildContent
    [
        SNew(SImage).Image(this, &SMyWidget::GetMyBrush, RandomVarToBind)
    ];
}

const FSlateBrush* SMyWidget::GetMyBrush(TSharedPtr<FMyType> RandomVarThatWasBound) const
{
    return (MySuperStateThatNeedsADifferentBrush)
        ? FMySlateStyle::Get().GetBrush("MySuperBrush")
        : FMySlateStyle::Get().GetBrush("MyNormalBrush");
}

```

---

<div class="post-metadata">

**Author:** ![StrangerGwenn](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/strangergwenn/32/983202_2.png) [@StrangerGwenn](https://forums.unrealengine.com/u/StrangerGwenn)\
**Post date:** [April 5, 2014, 9:50pm UTC](https://forums.unrealengine.com/t/manipulating-slate-content-during-and-after-construct/279697/7 "2014-04-05T21:50:08Z")

</div>

Yes, I just tried that. Slate really is awesome !

Thanks again. Hopefully I’m done with the noob questions 🙂

---

<div class="post-metadata">

**Author:** ![StrangerGwenn](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/strangergwenn/32/983202_2.png) [@StrangerGwenn](https://forums.unrealengine.com/u/StrangerGwenn)\
**Post date:** [April 12, 2014, 5:48am UTC](https://forums.unrealengine.com/t/manipulating-slate-content-during-and-after-construct/279697/8 "2014-04-12T05:48:47Z")

</div>

I need to use this in a subcomponent. A Slate widget has the method and passes it as a Slate parameter to a sub-widget that has the actual Image() construct.

Is this possible ? How should I declare the callback parameter ?

I tried this :

DECLARE\_DELEGATE\_RetVal(  
const FSlateBrush\*,  
FLoadImage)

SLATE\_ARGUMENT(FLoadImage, IconCallback)

But thill get this :

‘widgetname::FArguments::IconCallback’ : function does not take 3 arguments

How does it work for my OnClicked method ? How is FonReply different from my custom type ?

---

<div class="post-metadata">

**Author:** ![szyszek](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@szyszek](https://forums.unrealengine.com/u/szyszek)\
**Post date:** [April 12, 2014, 6:46am UTC](https://forums.unrealengine.com/t/manipulating-slate-content-during-and-after-construct/279697/9 "2014-04-12T06:46:10Z")

</div>

Use `SLATE_EVENT(FLoadImage, IconCallback)` instead

---

<div class="post-metadata">

**Author:** ![Jamie\_Dale](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/jamie_dale/32/1165413_2.png) [@Jamie\_Dale](https://forums.unrealengine.com/u/Jamie_Dale)\
**Post date:** [April 12, 2014, 10:35am UTC](https://forums.unrealengine.com/t/manipulating-slate-content-during-and-after-construct/279697/10 "2014-04-12T10:35:34Z")

</div>

Am I correct in my understanding that you have WidgetA, containing WidgetB, which contains an SImage, and that you need to pass a delegate from WidgetA through to the SImage which will control the brush used?

If so, you’d simply use a SLATE\_ATTRIBUTE on WidgetB in the same way that SImage uses a SLATE\_ATTRIBUTE to specify the brush used.

```
SLATE_ATTRIBUTE(const FSlateBrush*, IconCallback)

```

You would then forward that directly through to the SImage.

```
SNew(SImage).Image(InArgs._IconCallback)

```

---

<div class="post-metadata">

**Author:** ![StrangerGwenn](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/strangergwenn/32/983202_2.png) [@StrangerGwenn](https://forums.unrealengine.com/u/StrangerGwenn)\
**Post date:** [April 12, 2014, 11:55am UTC](https://forums.unrealengine.com/t/manipulating-slate-content-during-and-after-construct/279697/11 "2014-04-12T11:55:29Z")

</div>

Yes you are, and it works ! As always 🙂

Thank you for your help !

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_a231870a](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_a231870a](https://forums.unrealengine.com/u/anonymous_user_a231870a)\
**Post date:** [April 24, 2021, 7:07pm UTC](https://forums.unrealengine.com/t/manipulating-slate-content-during-and-after-construct/279697/12 "2021-04-24T19:07:24Z")

</div>

Can you guys just point me to some of good tutorials or documentation of slates. i have just started it , but its hard to find any resources on that
