Hi!
How could I pass a member function that will be used in .AddDynamic as parameter?
Example:
void ACustomActor::CreateMessage(**/* what type should I use here? */**)
{
MessageWidget = CreateWidget<UMessageUserWidget>(this, MessageWidgetClass);
MessageWidget->AddToViewport();
MessageWidget->OpenMessage();
// **So I could replace hard code here:**
//MessageWidget->OnCloseMessage.AddDynamic(this, **&ACustomActor::CloseMessage**);
}
So I could call it as:
CreateMessage(**&ACustomActor::CloseMessage**);
I couldn’t even create a variable from it, it didn’t compile:
TFunction<void(ACustomActor::*)(void)> Function = &ACustomActor::CloseMessage;
I’m trying to do it more Unreal than pure C++ as it need to be UFUNCTION() and I don’t know if it could have leaks or other problems.
Oh yeah, right. AddDynamic is a macro not only bounds function, but also “extracting” function name in preprocessor stage.
This can be solved by creating a simple wrapper class, but internet say UFUNCTION don’t allow function pointer of any types (raw,TFunction,etc.) as a param.
So, actually I don’t see any other option than wrapping it in UObject* like: