the functions currently call each other in this order CharacterFunc1, PCFunc(with value = 0), GMFunc, PCFunc(with value = 2 but skipping the character cast), PCFunc, PCFunc, CharacterFunc1, PCFunc(with value = 0)
i want it to CharacterFunc1, PCFunc(with value = 0), GMFunc, PCFunc(with value = 2), CharacterFunc2
void AShooterCharacter::CharacterFunc1()
{
AShooterPlayerController* PC = Cast<AShooterPlayerController>(UGameplayStatics::GetPlayerController(GetWorld(), 0));
if (PC)
{
PC->PCFunc(0);
}
}
void AShooterCharacter::CharacterFunc2(int32 Value)
{
Variable = Value;
}
void AShooterPlayerController::PCFunc(int32 Value)
{
if (Value == 0)
{
AShooterGameMode* GMM = Cast<AShooterGameMode>(UGameplayStatics::GetGameMode(GetWorld()));
if (GMM)
{
GMM->GMFunc();
}
}
else
{
AShooterCharacter* Character = Cast<AShooterCharacter>(GetCharacter());
if (Character)
{
Character->CharacterFunc2(Value);
}
}
}
void AShooterGameMode::GMFunc()
{
AShooterPlayerController* ShooterPC = Cast<AShooterPlayerController>(UGameplayStatics::GetPlayerController(GetWorld(), 0));
if (ShooterPC)
{
ShooterPC->PCFunc(2);
}
}
one is that when i cast to gamemode and call a function in gamemode that then calls a function in character and passes a variable i cant do anything with the variable
the problem is that the TestNewVariable function returns the ChangingVariable but it is 0 when it should be 2
BTW TestNewVariable func is binded to keyboard key
RetrieveVariable() is in the playercontroller or in the character? From the code above, RetrieveVariable in the character but you’re calling it in the character.
Do you have a RetrieveVariable() function in both the character and in the controller?
Sorry, I’m just not getting it. It makes no sense to me.
An interaction diagram would be very helpful to fully understand the flow of data and communications.
So, who and where is setting that variable?
If, for example, the value of the variable is set from a key event in the PC, then when it’s set in the PC, you also set it directly in the GM. No need for GM to go to PC to get that value.