PREDALIEN
(PREDALIEN)
May 19, 2025, 10:41am
1
Hi all.
I have an “inventory”, and some items have dynamic parameters.
I use the standard serialization of the engine to store them.
And I often need to get the value of these parameters, but the object itself is not needed at this moment.
Is it possible to get the value of a variable by its name from byte array, similar to how it can be done with UProperty?
For now I create a buffer object (of the same class), “smear” serialized data on it, and get the value of the variable I need from it.
Is it possible to somehow make this process neater, or something like that?
Thanks in advance.
Ivan3z
(Ivan3z)
May 19, 2025, 10:50am
2
I think you can use FMemoryReader and FMemoryWrite
bool Var1 = true;
uint32 Var2 = 40;
float Var3 = 3.1415f;
FString Var4 = "Hello Dude"
TArray<uint8> Encode()
{
TArray<uint8> Payload;
FMemoryWriter Ar(Payload);
Ar << Var1;
Ar << Var2;
Ar << Var3;
Ar << Var4;
return Payload;
}
void Decode(const TArray<uint8>& Payload)
{
FMemoryReader Ar(Payload);
Ar << Var1;
Ar << Var2;
Ar << Var3;
Ar << Var4;
}
But i think you must read in the same order it was wrote (if you have more than one varible in the array).
1 Like
PREDALIEN
(PREDALIEN)
May 19, 2025, 11:10am
3
I was close, but I couldn’t see it point-blank…
FMemoryReader “erases” itself during reading? Is that what you mean?
Can you show an example for reading/writing two variables into one array?
Ivan3z
(Ivan3z)
May 19, 2025, 11:12am
4
Ok… I going to edid my previus answer… wait a minute
1 Like
PREDALIEN
(PREDALIEN)
May 19, 2025, 11:19am
6
Looks like something I’ve always wanted to have.
All I have to do is attach an interface to the objects so that they can give/receive data from the storage.
Thank you!
1 Like
Ivan3z
(Ivan3z)
May 19, 2025, 11:23am
7
I’m not sure with FMemoryReader and FMemoryWrite
But when i serialize something using std::memcpy() and a std::vector YES… i removed the variable from the array… maybe FMemoryReader and FMemoryWrite work in a different way but i realy don’t know
I glad to help you!!
1 Like