# Set FString Variable in function

**URL:** <https://forums.unrealengine.com/t/set-fstring-variable-in-function/341842>\
**Category:** Editor Scripting\
**Tags:** Variable, fstring, unreal-engine, question, CPP\
**Created:** [December 18, 2015, 5:25pm UTC](https://forums.unrealengine.com/t/set-fstring-variable-in-function/341842 "2015-12-18T17:25:23Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![edcolmar](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@edcolmar](https://forums.unrealengine.com/u/edcolmar)\
**Post date:** [December 18, 2015, 5:25pm UTC](https://forums.unrealengine.com/t/set-fstring-variable-in-function/341842/1 "2015-12-18T17:25:23Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![Maide](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Maide](https://forums.unrealengine.com/u/Maide)\
**Post date:** [December 18, 2015, 11:50pm UTC](https://forums.unrealengine.com/t/set-fstring-variable-in-function/341842/2 "2015-12-18T23:50:50Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![joeGraf](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@joeGraf](https://forums.unrealengine.com/u/joeGraf)\
**Post date:** [December 19, 2015, 12:10am UTC](https://forums.unrealengine.com/t/set-fstring-variable-in-function/341842/3 "2015-12-19T00:10:05Z")

</div>

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

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

---

<div class="post-metadata">

**Author:** ![edcolmar](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@edcolmar](https://forums.unrealengine.com/u/edcolmar)\
**Post date:** [December 19, 2015, 12:47am UTC](https://forums.unrealengine.com/t/set-fstring-variable-in-function/341842/4 "2015-12-19T00:47:58Z")

</div>

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
```

---

<div class="post-metadata">

**Author:** ![edcolmar](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@edcolmar](https://forums.unrealengine.com/u/edcolmar)\
**Post date:** [December 19, 2015, 1:44am UTC](https://forums.unrealengine.com/t/set-fstring-variable-in-function/341842/5 "2015-12-19T01:44:40Z")

</div>

I must have mistakes in the blueprints:

 ![71216-ss2.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/6/2/0/62034ec2dcfa585ff0f6312089640fb0ff3cf70a.png)

 ![71217-ss3.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/3/2/4/3247c3cfae0e9d3451a0f450ad2a8c3417ef4f52.png)

---

<div class="post-metadata">

**Author:** ![joeGraf](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@joeGraf](https://forums.unrealengine.com/u/joeGraf)\
**Post date:** [December 19, 2015, 2:58pm UTC](https://forums.unrealengine.com/t/set-fstring-variable-in-function/341842/6 "2015-12-19T14:58:42Z")

</div>

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