Haha, yeah it seems like you’ve managed by bad luck to go through all combinations that don’t work before finding the one that does.
Okay, so yeah the delegate expects a pointer which you’ve now sorted.
Also, when you use the _Static binding, you shouldn’t pass in the this pointer at all, since it isn’t binding to any particular object instance. I’d be surprised if it compiles if you do.
Now, the delegate requires a function returning const FSlateBrush*, but that doesn’t mean your variable PreviewImageBrush needs to be either const, or a pointer. You can very well define it as:
static FSlateBrush PreviewImageBrush;
You can then initialize or change it whenever you like. You’d just need to alter your function to be:
const FSlateBrush* FOctaneRenderPluginModule::GetPreviewImage() const{
return &UOctaneOutput::PreviewImageBrush;
}
So you take the address of an FSlateBrush, yielding a type of FSlateBrush*, which can be converted to const FSlateBrush* no problem. You can always add constness, you just can’t take it away. Adding constness is just like saying “I have a variable that I’m allowed to modify, but I’m giving it to you in const form, so you can’t modify it.”
Now, hopefully that should be enough to get things working. If so you can skip what I’m about to add if you like, otherwise, read on at your peril.
Slate delegates are used to provide a dynamic attribute to a widget - instead of just passing it a value, you pass it a delegate and tell Slate: “Whenever you need this value, call this function to get it”. That way, you have complete control over what value Slate sees at any time. The thing is, here all your delegate function is doing is just returning a pointer to the same static variable every time. There’s no conditional logic in your function, so you don’t need a delegate at all. You could just as well have written:
SNew(SImage).Image(&UOctaneOutput::PreviewImageBrush)
It’s made complicated by the fact that pointers are involved. Compare it to this:
SNew(STextBlock).Text(MyFTextVariable)
This is passing a copy of a text variable to a widget at construction. That means if you subsequently change the value of MyFTextVariable, it won’t be reflected by the widget. In this case, you would want to use a delegate. That way Slate will get a new copy of the updated text every time.
With the case of SImage, you are giving Slate a pointer to a brush. The internals of that brush may change (for example, the UTexture2D inside it), but the brush itself is always UOctaneOutput::PreviewImageBrush. So you can do without the delegate. Whenever Slate needs to use the brush, it’s going to follow that pointer and access its contents. If the contents have been changed, that will be reflected automatically. Telling Slate every frame, “Hey, here’s the pointer to my brush” is superfluous, since the pointer is the same every time.
Hope that doesn’t add too much extra confusion!