Announcement

Collapse
No announcement yet.

Check if Interface Variable is typeof X

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Check if Interface Variable is typeof X

    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?

    Click image for larger version  Name:	2018-04-26 03_25_12-BP_InputManager_.png Views:	1 Size:	61.3 KB ID:	1466877

    In C# I would've simply written this:

    Code:
    public void RemoveMode<T>(){
        foreach(var e in inputModes){
            if(e is T){
                inputModes.Remove(e);
                return;
            }
        }
    }
    Last edited by TriNityGER; 04-25-2018, 09:37 PM.

    #2
    Guess I had to go C++:

    Code:
    //.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.

    Comment


      #3
      Actually there is a way to do it in BP only but its somewhat messy:
      Click image for larger version

Name:	2018-04-29 20_36_44-BP_InputManager_.png
Views:	9
Size:	24.0 KB
ID:	1468584

      Comment

      Working...
      X