Casting slate widgets

You’re trying to cast to a value type, which means you’re telling the compiler to try to construct a new object from the result of Get(). Your first line is equivalent to using static_cast, but still all that means is constructing an STextBlock from an SWidget, instead of casting it.

What you want to do is cast the reference, like so:

static_cast< STextBlock& >(this->ContentSlot->GetWidget().Get())

This way, you’re not copying the object, you’re casting a reference to it. The choice between static_cast and dynamic_cast is yours, although dynamic_cast can only be used with a pointer, since references are not nullable:

dynamic_cast< STextBlock* >(&this->ContentSlot->GetWidget().Get())

More excellent reading on the subject here.