All of UE4’s Serialize functions are dual operation - they work on both readers and writers. If you call SerializeBin with a reader archive instead of a writer archive, it will deserialise for you:
TArray Storage;
UStruct* MyStruct = FMyStruct::StaticStruct();
FMyStruct Before;
FMemoryWriter ArWriter(Storage);
MyStruct->SerializeBin(ArWriter, &Before);
FMyStruct After;
FMemoryReader ArReader(Storage);
MyStruct->SerializeBin(ArReader, &After);
// Before and After should now be equal
Hope this helps,
Steve
发现UE里很多问题度娘根本无法解决,只能科学上网去解决
大致翻译一下 就是SerializeBin这个函数可以序列化,也可以反序列化,参数传FMemoryWriter就是序列化,传FMemoryReader就是反序列化
比如你有一个自定义的FInputMsg
则大致的序列化和反序列化函数如下
UNetHelper.h
UFUNCTION(BlueprintCallable)
static TArray<uint8> SerializeUserInputToBinaryArray(FInputMsg inputMessage );
UFUNCTION(BlueprintCallable)
static FInputMsg UnSerializeBinaryArrayToUserI