Sending Textures by Fragmentation

Hello.

We are experimenting with Unity Transport to distribute different types of data among clients, one of such types would be a Texture2D, we can extract the raw bytes of the Texture to send it through the Network but it’s much bigger than allowed.

I can’t find a guide on how to use the FragmentationPipeline correctly, I can only guess some things from the documentation but I’ve yet to make a working demo. Could you please point me in the right direction or show me an example of the correct implementation? Everything else is working great and seems pretty straight forward.

Unity 2020.3.16f1
Transport 0.8.0

hello
as I know unity web request (UnityWebRequestTexture.GetTexture) may helps you . take a look at the link.

1 Like

Thank you for the suggestion! however the Textures and data I’m trying to transfer are generated in real time and I can’t have them previously stored on a web server.

Is Unity Transport not suited for such transfers? I would still like to learn to use the FragmentationPipeline.

In my opinion , Unity Transparent is a good option for making a real-time game,but it depends on many things such as your game and your code.
you want to send and receive the texture in real time, what is the size of each texture in byte ?
And how many concurrent users are going to send and receive these information at the same time?

The size is around 1,808,000 bytes and it would be enough to send it to one client but I want to send it as often as possible because it’s updated constantly in real time

there is a way to split your all bytes data by buffer.copyblock, check this link out .

1 Like

Thank you, I’m currently implementing my own fragmentation for big messages and I will use copyblock as you suggested until I can find more information or documentation on the FragmentationPipeline.

1 Like

this is an example, hope this help.

//for sending every 4 bytes :

byte[] Allbytes = new byte[8];
        byte[] midByte = new byte[4];
        byte[] evByte = new byte[4];
        midByte = BitConverter.GetBytes(whatever);
        evByte = BitConverter.GetBytes(whatever);
        Buffer.BlockCopy(midByte , 0, Allbytes, 0, 4);
        Buffer.BlockCopy(evByte , 0, Allbytes, 4, 4);
       NativeArray<byte> ConvertedByte = new NativeArray<byte>(Allbytes, Allocator.Temp);

        NetworkPipeline UnreliablePipline = _unreliablePipline;

        if (_clientDrive.BeginSend(UnreliablePipline, _networkConnection, out var _sendReliableData) == 0)
        {
            _sendReliableData.WriteBytes(ConvertedByte);
            _clientDrive.EndSend(_sendReliableData);
        }


//for receieving every 4 bytes :
 
byte[] Allbytes = new byte[8];
    byte[] midbyte= new byte[4];
        byte[] evbyte= new byte[4];
        Buffer.BlockCopy(Allbytes, 0, midbyte, 0, 4);
        Buffer.BlockCopy(Allbytes, 4, evbyte, 0, 4);
        int userid = BitConverter.ToInt32(midbyte, 0);
        Int16 condition = BitConverter.ToInt16(evbyte, 0);


// you can convert to string as below
Encoding.ASCII.GetString(stringbyte);