Download

Accessing Aplayer State C++ variables in blueprints

Hello Everyone,

Quick question regarding accessing variables from the C++ Aplayer state in blueprints. How would one go about using the ShooterGame template and accessing variables such as these in blueprints? I’ve tried calling player state variables in the preset Pawn blueprint but can only access score it seems like. Thank you for any help regarding this.

AShooterPlayerState::AShooterPlayerState(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer)
{
TeamNumber = 0;
NumKills = 0;
NumDeaths = 0;
NumBulletsFired = 0;
NumRocketsFired = 0;
bQuitter = false;
}

void AShooterPlayerState::Reset()
{
Super::Reset();

//PlayerStates persist across seamless travel.  Keep the same teams as previous match.
//SetTeamNum(0);
NumKills = 0;
NumDeaths = 0;
NumBulletsFired = 0;
NumRocketsFired = 0;
bQuitter = false;

}

To give you an idea what I am trying to do…I am trying to design a new HUD for the ShooterGame using UMG and need to access Kills,Score,Ammo etc variables from the C++ variables as seen on the default HUD here:

FwrShoy.jpg

You need to go into the .h file and add the following above each variable:



UPROPERTY(BlueprintReadOnly, Category = "SomeCategory")


Bear in mind, all of ShooterGames’ UI is done in Slate, not UMG - so unless you change a lot of other parts of the code too you won’t be able to use UMG to build the interface.

So I went ahead and applied the code you had mentioned and I do see it is callable but now Im stuck on why I can’t connect the node from player state to target(self)…Also in order to call NumKills i have to turn off contxt sensitive in order to see it.

1.jpg

2.jpg

Also as you see the Score variable is able to connect to the player state no problems by default. And also this screenie shows the variables I can access from player state which doesn’t include the new NumKills

3.jpg

Nevermind got it…I had to add cast to shooter player state…Thanks TheJamsh!