I’ve hit a wall while trying to write a custom NetSerialize method.
What I’m basically doing is serializing some primitive values and a texture. The primitive values are serialized with the << operator of FArchive and the texture is serialized with UTexture2D::Serialize(FArchive&). Well, I try to serialize it this way, but I hit an assert on runtime:
Bad archive positions for bulkdata.
StartPos=-1 EndPos=-1
What am I doing wrong? Did anyone successfully serialized a texture this way?
Hi! Is this texture is from Content folder or is it generated dynamically during your game? The first case can be saved by asset path, the second - by TArray (binary representation of bitmaps)
It’s a dynamic texture (I use USceneCaptureComponent2D to render the scene to a texture).
I’ll try to send it as TArray as you suggest, but I’m afraid that it’ll result in a similar error to the one I got while trying to send the texture like this
So I tried doing this with a smaller texture and it actually worked. Then I tried to chunk it but I’m still getting the message
LogNetPartialBunch: Error: Attempted to send bunch exceeding max allowed size. BunchSize=2097167, MaximumSize=65536
as if you couldn’t serialize 1024 bytes at once in NetSerialize
Thank you very much for the solution! I am trying to do the same, but for some reason it seems like the Ar.AttachBulkData does not modify my FArchive at all. I assume the method might only be supported by some archives.
I’m using FBufferArchive and its size isn’t modified at all with this command, even though the textureWidth etc. do get saved in it correctly. I do check BulkData size beforehand, and the data is definitely there, it just doesn’t get attached.
Which archive type do you pass as parameter into this function in your implementation? Should it be FMemoryWriter?
I had run into an issue using the code provided by woookie2na2, as the AttachBulkData method did not do anything to the FArchvie for some reason.
I ended up using Texture->PlatformData->Mips[0].BulkData->Serialize(DataArchive, nullptr) instead of both the AttachBulkData and DetachBulkData.
I don’t know if it works for really big textures, I didn’t test that as it isn’t needed for my use case. Just wanted to mention this as an alternative solution, in case people run into the same issue.
I was using this for saving/loading files, but it can be used for network serialization too I suppose. Just in cases here is the file IO functions, which are using the above functions: