# Variable input name and value to string

**URL:** <https://forums.unrealengine.com/t/variable-input-name-and-value-to-string/477763>\
**Category:** Editor Scripting\
**Tags:** Variable, value, string, Input, unreal-engine, name, question\
**Created:** [January 25, 2021, 3:33pm UTC](https://forums.unrealengine.com/t/variable-input-name-and-value-to-string/477763 "2021-01-25T15:33:09Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![visualart](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@visualart](https://forums.unrealengine.com/u/visualart)\
**Post date:** [January 25, 2021, 3:33pm UTC](https://forums.unrealengine.com/t/variable-input-name-and-value-to-string/477763/1 "2021-01-25T15:33:09Z")

</div>

Hi, currently trying to learn some C++ coding.  
What I try to do is to have a node that basically converts a variable to a string, defined as “VariableName, Value”.

Any ideas on achieving that ? I can’t seem to be able to get the name exposed of the input.

> **[variable2string](https://ibb.co/1nhzMRf)**
>
> Image variable2string hosted in ImgBB

thanks in advance.

---

<div class="post-metadata">

**Author:** ![Kehel18](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Kehel18](https://forums.unrealengine.com/u/Kehel18)\
**Post date:** [January 25, 2021, 3:49pm UTC](https://forums.unrealengine.com/t/variable-input-name-and-value-to-string/477763/2 "2021-01-25T15:49:49Z")

</div>

Hello! In C++ you can define MACRO and use #x to get name of the variable x. This is used in Engine code as well, for example if you search for #x you can find these useful MACROS:

- MSC\_FORMAT\_DIAGNOSTIC\_HELPER
- PREPROCESSOR\_TO\_STRING and etc

---

<div class="post-metadata">

**Author:** ![visualart](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@visualart](https://forums.unrealengine.com/u/visualart)\
**Post date:** [January 25, 2021, 4:08pm UTC](https://forums.unrealengine.com/t/variable-input-name-and-value-to-string/477763/3 "2021-01-25T16:08:29Z")

</div>

Hi Kehel18, thanks for the reply, since i’m still trying to grasp how everything works, how would that look like in code ?

What I have so far is (manually setting the variable name in UE)

// Convert variable to name and value string  
bool USaveTxtFile::VariableToString(FString VariableName, float VariableInFloat, int32 VariableInInteger, FString VariableInString, FString& StringOut)  
{  
StringOut = VariableName + TEXT(",") + FString::FromInt(VariableInInteger);

```
//StringOut = VariableName + TEXT(",") + FString::SanitizeFloat(VariableInFloat);
//StringOut = VariableName + TEXT(",") + VariableInString;
	
return true;

```

}

---

<div class="post-metadata">

**Author:** ![visualart](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@visualart](https://forums.unrealengine.com/u/visualart)\
**Post date:** [January 25, 2021, 4:08pm UTC](https://forums.unrealengine.com/t/variable-input-name-and-value-to-string/477763/4 "2021-01-25T16:08:51Z")

</div>

Hi Kehel18, thanks for the reply, since i’m still trying to grasp how everything works, how would that look like in code ?

What I have so far is (manually setting the variable name in UE)

// Convert variable to name and value string  
bool USaveTxtFile::VariableToString(FString VariableName, float VariableInFloat, int32 VariableInInteger, FString VariableInString, FString& StringOut)  
{  
StringOut = VariableName + TEXT(",") + FString::FromInt(VariableInInteger);

```
//StringOut = VariableName + TEXT(",") + FString::SanitizeFloat(VariableInFloat);
//StringOut = VariableName + TEXT(",") + VariableInString;
	
return true;

```

}

---

<div class="post-metadata">

**Author:** ![Kehel18](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Kehel18](https://forums.unrealengine.com/u/Kehel18)\
**Post date:** [January 25, 2021, 5:03pm UTC](https://forums.unrealengine.com/t/variable-input-name-and-value-to-string/477763/5 "2021-01-25T17:03:26Z")

</div>

Just take a look at this [c++ - print variable name in a #define - Stack Overflow](https://stackoverflow.com/questions/7766115/print-variable-name-in-a-define?rq=1)

---

<div class="post-metadata">

**Author:** ![visualart](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@visualart](https://forums.unrealengine.com/u/visualart)\
**Post date:** [January 25, 2021, 6:01pm UTC](https://forums.unrealengine.com/t/variable-input-name-and-value-to-string/477763/6 "2021-01-25T18:01:31Z")

</div>

As far as I got it gives me the name of the variable that is defined in the c++ code, not the one of the node that is attached to it in Unreal. Is that correct ?

---

<div class="post-metadata">

**Author:** ![Kehel18](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Kehel18](https://forums.unrealengine.com/u/Kehel18)\
**Post date:** [January 27, 2021, 4:52pm UTC](https://forums.unrealengine.com/t/variable-input-name-and-value-to-string/477763/7 "2021-01-27T16:52:59Z")

</div>

I was thinking that you need it in C++ because you have pointed that you are learning some code. Do you need that for Blueprint variables?

---

<div class="post-metadata">

**Author:** ![visualart](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@visualart](https://forums.unrealengine.com/u/visualart)\
**Post date:** [January 27, 2021, 5:11pm UTC](https://forums.unrealengine.com/t/variable-input-name-and-value-to-string/477763/8 "2021-01-27T17:11:14Z")

</div>

Yes but I want to get to the node that is attached to the input of the C++

---

<div class="post-metadata">

**Author:** ![Kehel18](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Kehel18](https://forums.unrealengine.com/u/Kehel18)\
**Post date:** [January 27, 2021, 5:31pm UTC](https://forums.unrealengine.com/t/variable-input-name-and-value-to-string/477763/9 "2021-01-27T17:31:50Z")

</div>

Brrr ) I dond understand what are you searching ) You have **BP variable node** and search for **BP node** that will get some info from **variable node** and will have _“VariableName, Value”_ formatted string as output, right? Or you want to create that kind of node?

---

<div class="post-metadata">

**Author:** ![visualart](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@visualart](https://forums.unrealengine.com/u/visualart)\
**Post date:** [January 27, 2021, 5:39pm UTC](https://forums.unrealengine.com/t/variable-input-name-and-value-to-string/477763/10 "2021-01-27T17:39:52Z")

</div>

hahaha let me try to clarify, so what i’m trying to do is create a blueprintnode with C++ that can function as a vault to store variables into a local file. Ideally no matter what variable node you would plug into it (wildcard), the C++ blueprintnode uses the name of the variable and the value and stores it into a stringmap so that later on you can use the name and value to feed again in unreal. There is the option in Unreal to store variables to a configfile but it reloads only after build so I’m trying to make it work whenever I want with a simple save/load.

Does that make more sense ?

---

<div class="post-metadata">

**Author:** ![Kehel18](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Kehel18](https://forums.unrealengine.com/u/Kehel18)\
**Post date:** [January 29, 2021, 4:37pm UTC](https://forums.unrealengine.com/t/variable-input-name-and-value-to-string/477763/11 "2021-01-29T16:37:54Z")

</div>

At last I understand you )) Can you try this

```
FString VariableToString2(const FString& VariableName, float VariableInFloat, int32 VariableInInteger, const FString& VariableInString, FString& StringOut) {
		...
}
```

---

<div class="post-metadata">

**Author:** ![Ppasterz](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Ppasterz](https://forums.unrealengine.com/u/Ppasterz)\
**Post date:** [January 19, 2024, 10:24pm UTC](https://forums.unrealengine.com/t/variable-input-name-and-value-to-string/477763/12 "2024-01-19T22:24:32Z")

</div>

I found something like this:

#define TT(Value) FString::Printf(TEXT(“%s: %i”),TEXT(#value), Value)

int z = 5;  
UE\_LOG(LogTemp, Warning, TEXT(“%s”), \*TT(z));

Ofcourse this works only for int. For now I’am working on class that could represend logs like std::cout to the console, and you could print variable with name.
