How do I use an interface type as a UPROPERTY in c++? For example, in Blueprint the function GetAllActorsWithInterface takes an interface type as an argument. How could I make a C++ class which had a UFUNCTION like this or a UPROPERTY like this?
The reason smart pointer is needed is that garbage collector is not interface-aware. Please note, that you need to assign it via the UObject type instead of the interface type. Also, nulling this pointer requires an explicit cast:
I think what you are saying is that if I want a property which can be an instance of an object which implements IUsableInterface then I can use TScriptInterface. Is that right?
What I actually want is to be able to pass an interface class like GetAllActorsOfInterface.
For example, I want to be able to do something like
UPROPERTY
UClass* DesiredInterfaceType;
and then be able to do something in C++ to all actors which implement that interface.
Maybe the clearest way to say it is as follows: “How would I implement GetAllActorsOfInterface in C++ so that the interface was specified in blueprint but the function was implemented in C++?”