Set variable from outside

hey guys I am switching my nodes into c++. I need to set this variable (called from the player controller) from this actor bp. How can I do this in c++? Do I have to cast? Thanks guyssss :smiley:

So if I understand this correctly, “RespawnTimes” is an int in your custom player controller. “Add” is an int in this actor, and that’s the amount you want to set “RespawnTimes” to be. You should rename “Add” to something more reasonable though.



// Get the local player's player controller.
APlayerController* LocalPlayerController = GetWorld()->GetFirstPlayerController();
if (LocalPlayerController)
{
     // If the local player controller is not null, cast it to our custom player controller class.
     AMyCustomPlayerController* MyCustomPlayerController = Cast<AMyCustomPlayerController>(LocalPlayerController);
     if (MyCustomPlayerController)
     {
          // If the cast was succcessful, set the variable.
          MyCustomPlayerController->RespawnTimes = Add;
     }
}


Cool thanks a lot dude!!! :smiley: Yes I was just posting an example with a random variable name, it was more to understand how should I work on these kind of situations Thanks for your help I really appreciate