# Issue on serialize FTransform Property to byte stream

**URL:** <https://forums.unrealengine.com/t/issue-on-serialize-ftransform-property-to-byte-stream/479370>\
**Category:** Editor Scripting\
**Tags:** ustruct, serialization, unreal-engine, question, CPP\
**Created:** [February 25, 2021, 1:41am UTC](https://forums.unrealengine.com/t/issue-on-serialize-ftransform-property-to-byte-stream/479370 "2021-02-25T01:41:37Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Asahi\_86](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Asahi\_86](https://forums.unrealengine.com/u/Asahi_86)\
**Post date:** [February 25, 2021, 1:41am UTC](https://forums.unrealengine.com/t/issue-on-serialize-ftransform-property-to-byte-stream/479370/1 "2021-02-25T01:41:37Z")

</div>

I have made a UStruct like this:

```
USTRUCT(BlueprintType)
struct FTestLocation
{
	GENERATED_BODY()

	UPROPERTY()
	int32 Value = 0;

	UPROPERTY()
	FTransform Transfrom;

	UPROPERTY()
	float Value2 = 0;
};

```

And I am trying to serialize/deserialize with a Buffer.

```
FBufferArchive SavingStream;
FTestLocation SaveLocation;
SaveLocation.Value = 1;
SaveLocation.Transfrom.SetLocation({2.f, 2.f, 2.f});
SaveLocation.Value2 = 3.f;
FTestLocation::StaticStruct()->SerializeBin(SavingStream, &SaveLocation);

FBufferReader LoadingStream(SavingStream.GetData(), SavingStream.Num(), false);
FTestLocation LoadLocation;
FTestLocation::StaticStruct()->SerializeBin(LoadingStream, &LoadLocation);

```

The issue is: after the Loading process,

`LoadLocation.Value` is loaded correctly,

`LoadLocation.Transfrom` is not updated at all.

`LoadLocation.Value2 ` is clearly a trash value.

Can anyone let me know what I did wrong?

---

<div class="post-metadata">

**Author:** ![k\_a\_s\_s\_k\_a\_s\_s](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/k_a_s_s_k_a_s_s/32/555828_2.png) [@k\_a\_s\_s\_k\_a\_s\_s](https://forums.unrealengine.com/u/k_a_s_s_k_a_s_s)\
**Post date:** [February 25, 2021, 12:42pm UTC](https://forums.unrealengine.com/t/issue-on-serialize-ftransform-property-to-byte-stream/479370/2 "2021-02-25T12:42:02Z")

</div>

You can create a operator\<\< on the struct, which will serialize and deserialize easily from any archive.

In the struct, declare:

```
friend FArchive& operator<< (FArchive& Ar, FTestLocation& Struct);

```

Then, write an implementation in the global scope (so without namespace::), in the .cpp:

```
FArchive& operator<< (FArchive& Ar, FTestLocation& Struct) {
   Ar << Struct.Value;
   Ar << Struct.Transfrom;
   Ar << Struct.Value2;
   return Ar;
}

```

With this, any FArchive will correctly, in the same order, serialize and deserialize your struct to/from binary, just call `SomeFArchive << MyFTestLocation`, thanks to the fact that almost all Unreal types, such as FTransform, FVector, etc. have the operator\<\< overloaded already. You don’t have to worry about their internal structure, sizeof, things like that at all.

---

<div class="post-metadata">

**Author:** ![Asahi\_86](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Asahi\_86](https://forums.unrealengine.com/u/Asahi_86)\
**Post date:** [February 25, 2021, 1:19pm UTC](https://forums.unrealengine.com/t/issue-on-serialize-ftransform-property-to-byte-stream/479370/3 "2021-02-25T13:19:59Z")

</div>

Thanks for the reply, yes the solution you suggested could resolve my issue.  
But what I am working on is a `templated` solution using `SerializeBin` to work on all the `UStruct`, so Ideally I’d love to have something works without adding any new code.

Also, I am new to Unreal Engine, I am not sure if I am not using `SerializeBin` correctly, or this is a bug on `SerializeBin`? (I am going to dig into the implementation a bit later.)

---

<div class="post-metadata">

**Author:** ![Asahi\_86](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Asahi\_86](https://forums.unrealengine.com/u/Asahi_86)\
**Post date:** [February 25, 2021, 4:31pm UTC](https://forums.unrealengine.com/t/issue-on-serialize-ftransform-property-to-byte-stream/479370/4 "2021-02-25T16:31:23Z")

</div>

Found the issue by debugging into the `SerializeBin` implementation.

For the buffer Saved by `FBufferArchive` since it’s `FMemoryWriter`, I will need to use `FMemoryReader` to load it.

Change

```
FBufferReader LoadingStream(SavingStream.GetData(), SavingStream.Num(), false);

```

To

```
FMemoryReader LoadingStream(SavingStream);

```

Would resolve the issue.
