The end goal I want is to have some function essentially works like:
UFUNCTION(BlueprintCallable)
template<typename T>
AddTrackedData(UObject* objRef, [delegate T()] getterFunc, [delegate void(T)] setterFunc);
where [delegate T()]
is a delegate which returns T and [delegate void(T)]
is a delegate which takes a parameter T.
This is relatively straight-forward to do as a templated function, however, the UFUNCTION and other macros don’t seem to play nice with templates.
The function is used in order to create a new instance of DataTracker
template<typename T>
class DataTracker {
TWeakPtr<UObject> objRef;
T data;
};
Only instead of directly storing the data, I want to indirectly reference it using a getter and setter function like so
template<typename T>
class DataTracker {
public:
TWeakPtr<UObject> objRef;
DECLARE_DELEGATE_RetVal(T, FGetDelegate)
DECLARE_DELEGATE_OneParam(FSetDelegate, T)
FGetDelegate getValueFunction;
FSetDelegate setValueFunction;
};
If at all possible, I’d like to be able to set tracked data in blueprints, but I haven’t been able to figure out a way to go about that.