My game loads coordinates from a text file to initialize different objects like towers and props
So i gotta ask is there a way to load directly from a loaded string to a variable
(like example if i have 3 floats on a line of the text file can i do “%f %f %f, & propPos.x, & propPox.y, & propPos.z”?)
Actually it might to be possible to use stringstream (from header sstream). Basically it’s std library, so it should work on every platform.
The next code can be example of fragment of some .cpp file:
#include <string>
#include <sstream>
//...
//Somewhere in function body
std::stringstream reader(std::string(*SomeUEString));
reader >> float1 >> float2 >> float3;
There are actually many ways to do this in unreal including using a handrolled parsing algorithm,
BUT you could also very effectively use a .csv file as well:
I will assume your vector values are separated by “space bar”
you will have to include std string header
#include <string>
FVector yourVector;
FString yourString;
FString tempString;
int32 charCounter = 0;
bool enOfString = false;
float value = 0.0f;
// Iterate for number of values in vector if vector 3 than 3 times
// if vector 2 than 2 times etc.
for (int32 i = 0; i < 3; i++)
{
while (true)
{
if (charCounter >= yourString.Len())
{
enOfString = true;
break;
}
// If white line than vector value has
// been reeded convert it and continue with "for" loop
if (yourString[charCounter] == ' ')
{
value = std::stof(*tempString);
tempString.Reset();
charCounter++;
break;
}
else
{
tempString += yourString[charCounter];
}
}
switch (i)
{
case 0:
yourVector.X = value;
break;
case 1:
yourVector.Y = value;
break;
case 2:
yourVector.Z = value;
break;
}
if (enOfString) { break; }
}
Btw. the last value must be proceeded with “Space” to