Closed
Description
Describe the bug:
Passing spawnPayload to NetworkObject#Spaw(Steam) and reading stream from NetworkBehavior#NetworkStart(Stream), extra values are added.
Steps to reproduce the behavior:
- call Spawn method with spawnPayload.
var obj = Instantiate(SomePrefab);
var stream = new MemoryStream(Encoding.UTF8.GetBytes("helloworld"));
obj.GetComponent<NetworkedObject>().Spawn(stream.Stream);
- Read the value in NetworkStart
public override void NetworkStart(Stream stream)
{
base.NetworkStart(stream);
var memoryStream = new MemoryStream();
stream.CopyTo(memoryStream);
var message = Encoding.UTF8.GetString(memoryStream.ToArray());
Debug.Log(message);
}
- The log will be output as hello with a mysterious message.
helloworld��Dt`XD�����䒈Dt�D�����DtDpblld�f�Z�hfpZhhhhZ��p�Zrf��lbbln�r�D��
Expected behavior:
I think only helloworld should be output.
Desktop/Tablet/Smartphone (please complete the following information):
- OS: [e.g. iOS] windows10
- MLAPI v12.1.7
- Unity 2020.2.3.f1
Additional info:
Perhaps this problem is caused by something here in the code.
The buffer will be partially overwritten and extra information will be left behind.
if (payload != null) buffer.CopyFrom(payload);