C++ Cast NPC Character into Player Character

Hello World, C++ noob here. I have a project made in blueprint, and I’m trying to convert everything in C++.
I’m having only 1 problem. I have an NPC Character (NPCInteractive), an AI, and I want to cast it into my Player Character, because I have fonctions into my NPC that I want to call in my Player. Here is the CPP file:

    #include "WithLoveFromTahitiCharacter.h"
    #include "NPCInteractive.h"
    
    	// launch dialogue input
PlayerInputComponent->BindAction("LaunchDialogue", IE_Released, this, &AWithLoveFromTahitiCharacter::LaunchDialogue);
    
    void AWithLoveFromTahitiCharacter::LaunchDialogue()
    {
    	ANPCInteractive* NPCInteractive = Cast<ANPCInteractive>(GetOwner());
    
    	if (NPCInteractive != nullptr)
    	{
    		UE_LOG(LogTemp, Warning, TEXT("OVERLAP"))
    	}
    	else
    	{
    		UE_LOG(LogTemp, Warning, TEXT("NULL"))
    	}
    }

When I press the LaunchDialogue button, it return always NULL

Here is the .h file:

#include "WithLoveFromTahitiCharacter.generated.h"

class ANPCInteractive;

UCLASS(config=Game)
class AWithLoveFromTahitiCharacter : public ACharacter
{
 ...
}

Thank you for your help guys and sorry for my english (I’m stuck for 1 week now lol).

I’m really not sure what exactly you want to achieve.
How I understand what you want…
On Button Press you want to interact with an NPC.
And the Interaction is defined inside the NPC.

What I would do:
-On Button Press-> Get all overlapping actors of class npc / use traces to get the npc (depends on your System)
-Use the NPC reference to call your function

Hello sir, sorry for the late, you’re right, here is the blueprint for more details

So why dont you Just reproduce the blueprints in c++? They seem to be decent.
There should be more than enough resources to find about Bindung to the overlap Events in c++
And you should be good to go. Because currently you are missing any reference to the NPC so your cast will always fail

In the first post, I was just trying to understand how Cast work and yes right now I’m working with a OnComponentBeginOverlap event with cast, still not working XD but, I’m still learning :slight_smile: