How do I access variables from a component in C++?

Hello!

I have a health component that has the variables MaxHP and CurrentHP and I just need to access them onBeginPlay of my game mode (C++). So far I’m getting a reference to the player and the health component properly (i have print nodes that show the name of the component when not a nullptr) however, it says that the variables I’m trying to assign to PlayerMaxHP (an int var inside the game mode) is inaccessible when I use: PlayerMaxHP = PlayerHealthComponent->MaxHP();

PlayerMaxHP - variable inside the game mode
PlayerHealthComponent - the health component reference
MaxHP - the variable inside the said component

Any advice will do thank you!

Okay so I couldn’t figure this out until I remember getters exist for a reason.

What I did is basically I made a getter function inside the health component. It returns a value of the maxHP and then I set the value of the variable to the function call which returns the value of int.