Set FString Variable in function

Total noob here. Should be an easy one.

I am fetching a json string from http, and extracting out a string identifier. This works great.

I want to keep this identifier to use in a later function.

I have extended [project]Character.h and cpp to hold the code and the string, but it’s not working. Blueprints does not need to touch this variable once I have it.

Character.h

FString LeetPlatformId;

Character.cpp

ALEETDEMO2Character::LeetPlatformId = JsonParsed->GetStringField("player_platformid");
					UE_LOG(LogTemp, Log, TEXT("ALEETDEMO2Character::LeetPlatformId: %s"), *ALEETDEMO2Character::LeetPlatformId);

					LeetPlatformId = JsonParsed->GetStringField("player_platformid");
					UE_LOG(LogTemp, Log, TEXT("LeetPlatformId: %s"), *LeetPlatformId);

In the log, I see:

LogTemp: ALEETDEMO2Character::LeetPlatformId: REUFIR

LogTemp: LeetPlatformId: REUFIR

So far so good

But when I try to get this string in a different function:

Character.cpp

UE_LOG(LogTemp, Log, TEXT("LeetPlatformId: %s"), *LeetPlatformId);
	UE_LOG(LogTemp, Log, TEXT("ALEETDEMO2Character::LeetPlatformId: %s"), *ALEETDEMO2Character::LeetPlatformId);

This displays:

LogTemp: LeetPlatformId:

LogTemp: ALEETDEMO2Character::LeetPlatformId:

What am I doing wrong?

Thanks so much!

Are you accessing these variables on the server in one function, and on a client in the other? If so, you should look into variable replication.

Are you sure you’re accessing the same instance? Add the following to both functions:

UE_LOG(LogTemp, Log, TEXT("Object is: %s"), *GetName());

Thanks for the responses. This is single player, no replication.

Thanks for the helpful logging code. Here is the output:

LogTemp: LeetPlatformId: REUFIR
LogTemp: Object is: LEETDEMO2Character_31

LogTemp: LeetPlatformId: 
LogTemp: Object is: TP_2DSideScrollerCharacter_1

I must have mistakes in the blueprints:

That is your problem. You are operating on two different entities