How do I create a variable in C++ that stores a specific character? or accesses a specific character?

For instance, I want to create an enemy that only targets one specific character on screen. Right now I have the enemy walking towards the location of the player character using

ACharacter* MainCharacter = UGameplayStatics::GetPlayerCharacter(GetWorld(), 0);

and manipulating the Maincharacter stuff, but when I switch to a different playable character, now they start to target that character. I know why it does this, because it gets 0 on the player index and when I switch to the other character he is still player 0 index.

What I would like is to create a reference to main character of the game, and then when I switch to the second character, the enemy will still target that main character because they’re doing logic only with the reference of the main character.

In blueprint you solve this by doing a cast. Now I have very little knowledge how to use this correctly and I’d like an idea of how to do so.

I have ACharacter_Main
and ACharacter_Partner
and ACharacter_Enemy
if that helps…

Closed, because of duplication: