Again Thank you for your support EvilCleric
this is how i got it working
in this example what it does is get GM variable and set PC variable to be the same
and
the getGM sets the PC variable to the GM variable and TestVariableAmount function adds 1 to the variable and prints it out
character cpp
void AMyCharacter::BeginPlay()
{
Super::BeginPlay();
AMyPlayerController* ShooterPC = Cast<AMyPlayerController>(UGameplayStatics::GetPlayerController(GetWorld(), 0));
if (ShooterPC)
{
ShooterPC->getGM();
}
}
PlayerController cpp
void AMyPlayerController::SetupInputComponent()
{
Super::SetupInputComponent();
InputComponent->BindAction("TestVariableAmount", IE_Pressed, this, &AMyPlayerController::TestVariableAmount);
InputComponent->BindAction("ResetVariable", IE_Pressed, this, &AMyPlayerController::getGM);
}
void AMyPlayerController::getGM()
{
AtesttodeleteGameModeBase* GM = Cast<AtesttodeleteGameModeBase>(UGameplayStatics::GetGameMode(GetWorld()));
if (GM)
{
GM->GMFunc();
}
}
void AMyPlayerController::ReturnGM(int32 value)
{
PCVariable = value;
FString IntAsString = FString::FromInt(NewVariable);
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Orange, IntAsString);
}
void AMyPlayerController::TestVariableAmount()
{
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Orange, TEXT("NewVariable before adition"));
FString IntAsString = FString::FromInt(PCVariable );
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Orange, IntAsString);
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Purple, TEXT("NewVariable + 1"));
PCVariable += 1;
FString SecondString= FString::FromInt(PCVariable );
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Purple, SecondString);
}
GameMode cpp
AMyPlayerController* ShooterPC = Cast<AMyPlayerController>(UGameplayStatics::GetPlayerController(GetWorld(), 0));
if (ShooterPC)
{
ShooterPC->ReturnGM(2);
}