FObjectWriter and FObjectReader cannot reproducing UObject after reopen editor

Hello everyone! I use FObjectWriter to serialize a UObject to TArray buffer, then I use FObjectReader to reproduce the UObject, it works fine in engine editor. But when I close the engine then reopen it, the same TArray buffer cannot reproduce the UObject, always error value on some properties, anyone know this?

各位好!FObjectWriter和FObjectReader有谁了解吗?我用FObjectWriter记录一个UObject到TArray,然后用FObjectReader还原这个UObject,在引擎里正常使用没啥问题。但是只要关闭引擎再重新打开,那么同样的TArray数据就无法还原到UObject了,总是有些数据错误或者丢失,有谁了解吗?

1 Like

找到原因了:是FName引起的,默认FObjectWriter和FObjectReader这两个序列化工具对FName序列化的时候是存储的id号,但FName的id号是每次打开引擎的时候重新生成的,所以关闭后再打开引擎FName的id号就变了,那么序列化就失败了。把FName序列化成FString就好了。

Found the reason: Caused by FName serialization, by default the FObjectWriter and FObjectReader serialize FName by it’s id, but FName’s id is generated since engine start, so when reopen the engine the FName’s id will change, then deserialize action fails. Now I just serialize FName by FString.

2 Likes

我想请问下如何使用这个FObjectReader,如何获取obj指针的值呢

可以用两个自己的类分别继承FObjectReader和FObjectWriter,用自己的规则覆写object的序列化部分。我在制作LGUI插件的时候就是用的FObjectReader/Writer做出了类似unity的预制体系统。

1 Like