Skip to content

Extra value is added to the value passed by spawnPayload #782

Closed
@sowa-s

Description

@sowa-s

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:

  1. call Spawn method with spawnPayload.
var obj = Instantiate(SomePrefab);
var stream = new MemoryStream(Encoding.UTF8.GetBytes("helloworld"));
obj.GetComponent<NetworkedObject>().Spawn(stream.Stream);
  1. 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);
}
  1. 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);

https://github.com/Unity-Technologies/com.unity.multiplayer.mlapi/blob/023b64aeecaeee7461bdf989000ff9a796cfde1b/com.unity.multiplayer.mlapi/Runtime/Spawning/NetworkSpawnManager.cs#L511

Metadata

Metadata

Labels

type:supportQuestions or other support

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions