Cannot pass the correct reference to the playercontroller to my actor component

I have this actor component which acts as a state machine. For it to work, it needs to have a reference to the character and a reference to the playercontroller. I’m doing this in a networked environnement.

Here’s the idle state for example :

void UIdleState::EnterState()
{
	// logging enter state
	UE_LOG(StateMachine, Display, TEXT("EnterState: %i"), GetStateID());
}

void UIdleState::SetStateID(StateID NewID)
{
	_id = NewID;
}

void UIdleState::UpdateState()
{
	CheckSwitchStates();
}


void UIdleState::CheckSwitchStates()
{
	if (!Controller()) return;

	if (!Ctx()) return;

	if (Controller()->WantsToMove()) SwitchState(Ctx()->StateMachine->GetCurrentStateFactory()->Run());
	if (Controller()->WantsToJump()) SwitchState(Ctx()->StateMachine->GetCurrentStateFactory()->Jump());
}

void UIdleState::ExitState()
{
	// logging exit state
	UE_LOG(StateMachine, Display, TEXT("ExitState: %i"), GetStateID());
}

What happens is that the state machine component has a reference to the current state and just ticks the update function of whatever state we’re in like so :

// Called every frame
void UStateMachineComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
	Super::TickComponent(DeltaTime, TickType, ThisTickFunction);

	if (CurrentState) CurrentState->UpdateState();
}

Below is the component being attached to the character class.

// Sets default values
ABaseCharacter::ABaseCharacter()
{
	// ....
	// Create the state machine
	StateMachine = CreateDefaultSubobject<UStateMachineComponent>(TEXT("StateMachine"));
}

I have this function called “InitializeStateMachine” on the StateMachineComponent which is supposed to call another function called “Initialize” which stores a reference to the character and a reference to the playercontroller.

void UStateMachineComponent::InitializeStateMachine()
{
	// Create a new factory
	CurrentStateFactory = NewObject<UStateFactory>(this, UStateFactory::StaticClass(), NAME_None, RF_Transient, nullptr);

	// Pass-in the character reference
	CurrentStateFactory->Initialize(Cast<ACharacter>(GetOwner()));

	// Set the default state
	CurrentState = CurrentStateFactory->Idle();
	CurrentState->EnterState();
}

void UStateFactory::Initialize(ACharacter* InContext)
{
	check(InContext);
	check(InContext->Controller);
	
	if (!_context) _context = Cast<ABaseCharacter>(InContext);
	if (!_controller) _controller = Cast<ABasePlayerController>(InContext->Controller);
}

The State Factory is a UObject that holds references to the character and the player controller.

The issue is, for some reason, online, the player controller has multiple addresses. I’m guessing one for the one on the server and another one for the one on the client. (What even is the point of having a playercontroller on the server?) But I can’t pass the right reference to my state machine (the one on the server or on the client ?) It keeps getting the one on the server and of course, my character can’t move.

Besides, my check(InContext->Controller) keeps falling even though I call the InitializeStateMachine function FROM MY PLAYER CONTROLLER

void ABasePlayerController::OnPossess(APawn* aPawn)
{
	Super::OnPossess(aPawn);

	ABaseCharacter* BaseCharacter = Cast<ABaseCharacter>(aPawn);
	BaseCharacter->StateMachine->InitializeStateMachine();
}

OnPossess is only called on the server no ? How can I get the correct reference to my playercontroller ? Do I need to replicate anything ? How do I initialize my state machine when the game is done creating the character on the client AND the character has a valid controller ?