Simple problem:
I got an array of IInputModes and in my RemoveInputMode function I can specify a InputMode class type.
Now I simply want to iterate over the array to check if theres an implementation of IInputMode in that array that is the type of the given InputMode class type.
But how can I check if the array element is type of InputMode?
In C# I would’ve simply written this:
public void RemoveMode<T>(){
foreach(var e in inputModes){
if(e is T){
inputModes.Remove(e);
return;
}
}
}
Guess I had to go C++:
//.h
UENUM(BlueprintType)
enum class EInterfaceTypeOfResult : uint8
{
Success,
Failed
};
/**
*
*/
UCLASS()
class ARES_API UAresBPFunctionLibrary : public UBlueprintFunctionLibrary
{
GENERATED_BODY()
UFUNCTION(BlueprintCallable, Meta = (ExpandEnumAsExecs = "Branches"))
static void interfaceIsOfType(UClass* classType, TScriptInterface<IInterface> interface, EInterfaceTypeOfResult& branches);
};
//.cpp
void UAresBPFunctionLibrary::interfaceIsOfType(UClass* classType, TScriptInterface<IInterface> interface,
EInterfaceTypeOfResult& branches)
{
branches = interface.GetObject()->IsA(classType) ? EInterfaceTypeOfResult::Success : EInterfaceTypeOfResult::Failed;
}
If anyone got a BP only version, I’d love to see it.
Actually there is a way to do it in BP only but its somewhat messy: