Get variable from serialized data

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.

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

I was close, but I couldn’t see it point-blank… :laughing:

FMemoryReader “erases” itself during reading? Is that what you mean?
Can you show an example for reading/writing two variables into one array? :folded_hands:

Ok… I going to edid my previus answer… wait a minute

1 Like

it is Done!!

1 Like

Looks like something I’ve always wanted to have. :kissing_face_with_smiling_eyes:

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

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