C++ interface implemented in BP returns null when casted

Hi everyone :),

I’m having a trouble with something related to interfaces.

This is the story so far :

  • I created this interface in C++

    // This class does not need to be modified.
    UINTERFACE(Blueprintable)
    class UMetaPlayerCharacterInterface : public UInterface
    {
    GENERATED_BODY()
    };

    /**
    *
    */
    class CUSTOMCAMERA_API IMetaPlayerCharacterInterface
    {
    GENERATED_BODY()

     	// Add interface functions to this class. This is the class that will be inherited to implement this interface.
    
     UFUNCTION(BlueprintImplementableEvent, BlueprintCallable, Category = "Input")
     	bool GotMovementInput() const;
    
     UFUNCTION(BlueprintImplementableEvent, BlueprintCallable, Category = "Input")
     	float GetCameraTargetLength() const;
    

    };

  • I have a BP Actor, where I added this interface from BP Editor and I have my interface’s functions appearing under “INTERFACES”

  • Now I have this code :

     if (ViewTarget->GetClass()->ImplementsInterface(UMetaPlayerCharacterInterface::StaticClass()))
     {
     	UE_LOG(LogTemp, Warning, TEXT("Green"));
     }
     
     IMetaPlayerCharacterInterface* playerCharacter = Cast<IMetaPlayerCharacterInterface>(ViewTarget);
    
     if (!playerCharacter)
     {
     	return false;
     }
    

So the ImplementsInterface() returns TRUE, but the cast returns NULL. And according to the documentation… It should work.

Does anyone know if I’m missing something ?

Best regards everyone :slight_smile:

PS : Ah and if anyone knows how to make interfaces functions with arguments in c++ which do not appear in the Return node but in the Entry node, You make my day, no, my WEEK ^^

Alex