Since this is a non dynamic multicast delegate the following ways to bind come to mind:
Header:
#include "CoreMinimal.h"
#include "Templates/SharedPointer.h"
#include "Layout/WidgetPath.h"
#include "Input/Events.h"
#include "Widgets/SWidget.h"
CPP:
AddLambda
- Not tried.
AddRaw
- You cannot use raw method delegates with UObjects.
AddStatic
- Not static
AddSP
- AsShared is not a member of UXXXXXXXX
AddUFunction
- As a UFUNCTION: "Unable to find class, delegate, enum, or struct with name FWeakWidgetPath" (and the others)
AddUObject
- Compiles as long as I do not mark the function UFUNCTION.
AddWeakLambda
- Not tried.
AddThreadSafeSP
- Not tried.
None of the official documentation states that AddUObject to a method NOT marked UFUNCTION is a valid combination. The BenUI documentation states that it is not.
So this leaves me with the impression we have 10 ways to bind but none can do this?
Hmm AddUFunction is not compatible in this case because some parameters of the delegate are not BP-compatible, so you cannot have an UFUNCTION with a signature that matches the delegate signature.
AddUObject should work with non-UFUNCTIONS for non-dynamic delegates. They are bound directly by member function pointer.
Only dynamic delegates require UFUNCTIONS, they are bound by name and triggered via reflection system. Methods like AddUObject, AddStatic or AddLambda do not exist for dynamic delegates.
AddLambda is a good alternative, although I’d suggest using AddWeakLambda whenever possible as it will automatically cancel the delegate if the bound object gets destroyed.
In this specific scenario, you can use the weak lambda to trim out the incompatible parameters and trigger an UFUNCTION on the object.
Ah, that is great! I don’t need blueprint functionality on this method and the delegate is not dynamic so removing the UFUNCTION and using AddUObject would work just fine? Or does the AddWeakLambda provide the benefits AddUObject does not?