Unfortunately function templates are not supported with UFUNCTION. Someone has a PR that adds support for it here https://github.com/EpicGames/UnrealEngine/pull/6902 (you’ll need to be signed in and have your account linked in order to see). Hopefully it will be in a future version.
You would need to specify the types you want it to work with though from the example code
I Am Using MACRO Because There Are Several Location And Several Code Files Where I Wrote Same Line Of Code, So Basically Instead Of Writing Same Line Of Code I Used MACRO, It Successed,
From:
TearDown(); // Remove From Parent Current Widget
UUMGBase* StoreUI = CreateWidget<UUMGBase>(GetWorld(), StoreUIClass);
if (!StoreUI) return;
StoreUI->SetupWidget();
A macro is just a dumb text replacement that happens before compilation happens. It would only cause a crash if the expanded code would crash.
They’re best avoid precisely because they’re just a dumb text replacement. You can’t debug them, the compiler can’t tell you if you messed up as it will only see what the macro expanded to, etc.
UDerivedUMG* Thing = Setup<UDerivedUMG>(UIClass);
if (Thing)
{
// use Thing
}
So this would just be syntactic sugar for C++ code. The first should still work for BP. This is actually what the templated versions of GetController, GetPawn, GetOwner et al. do