Is there any way UNET's NetworkTransport.Receive method can accept a varying buffer size?

There doesn’t seem to be any overloaded methods that allow for varying buffer sizes. It seems like you have to enforce a consistent buffer size when sending/receiving data or somehow know ahead of time what the incoming bufferSize will be:

Yes, but you won’t find the answer anywhere in the documentation. The reason I mention that last bit isn’t just to be catty, it is also to point out that the way I have found is maybe not intended functionality, so may go away. Especially since they are about to overhaul networking…

But, after spending several hours banging away at different thoughts I had on how I would have implemented it, I found out how THEY implemented it. If you pass in a buffer array and buffer size greater than one and less than the actual size it needs it does nothing with your buffer, and does nothing with the message in the queue. So basically, if your buffer is too small it keeps giving you a chance to give it a big enough buffer. A rough example of how to use it is below, I use a network event args to pack everything together, but I think you can figure out what’s in it.

NetworkEventArgs netEvent = ReadNetwork();

if( recEvent.bufferSize < recEvent.dataSize )
	// buffer wasn't big enough, so specify the exact buffer size
	recEvent = ReadNetwork( recEvent.dataSize );

// Try to read the next message out of the queue with the specified buffer size
private NetworkEventArgs ReadNetwork( int bufferSize = 32 )
	int recHostId;
	int recConnectionId;
	int recChannelId;
	byte[] recBuffer = new byte[bufferSize];
	int dataSize;
	byte error;
	NetworkEventType recNetworkEvent = NetworkTransport.Receive( out recHostId,
		out recConnectionId,
		out recChannelId,
		out dataSize,
		out error );

	if( recNetworkEvent == NetworkEventType.Nothing ) return null;

	return new NetworkEventArgs( recNetworkEvent,recHostId,recConnectionId,recChannelId,recBuffer,bufferSize, dataSize, error );