MirrorNetworking / Mirror

#1 Open Source Unity Networking Library
https://mirror-networking.com
MIT License
5.21k stars 769 forks source link

When crossing assemblies, you may not be able to obtain the Reader/Writer defined by yourself. #3816

Closed pepoipod closed 1 month ago

pepoipod commented 6 months ago

Describe the bug ReaderWriterProcessor registers a custom Reader/Writer included in AssemblyReferences of CurrentAssembly. However, in a complicated case, when a NetworkMessage contained in AssemblyReferences requires a Reader/Writer that is not contained in its CurrentAssembly.AssemblyReferences, Reader<T>.read contains the one generated with Readers.GenerateClassOrStructReadFunction() will be inserted.

[IMPORTANT] How can we reproduce the issue, step by step:

  1. Create assembly A. Here we define a simple record and a custom Reader/Writer. By using { get; set; }, Readers.GenerateClassOrStructReadFunction() will not insert a value, making it easier to test.
  2. Create assembly B. Create a NetworkMessage here and set the record created in assembly A to the property.
  3. Create assembly C. References assembly B only. Write code that appropriately references NetworkMessage in C. Without this, it seems that it is not included in CurrentAssembly.AssemblyReferences.
  4. Create a new class in assembly B that inherits NetworkBehaviour. Add SyncList to the properties. The server adds a random value to the SyncList during Update, etc.
  5. Start two Unity app using PararelSync etc. and check the behavior on Server / Client. The Count of SyncList is increasing and the contents are also increasing, but the value received by the Client is always the initial value.

Expected behavior The value incremented by SyncList must be set correctly.

Desktop (please complete the following information):

Additional context I fixed this issue locally. also ready to submit a PullRequest. If you don't mind, could you add me as a contributor?

miwarnec commented 4 months ago

Hey @pepoipod how did you fix this? You should be able to open a PR if you fork Mirror, create a branch with your change, push it, and then go to mirror -> pull requests, github will suggest you to open your branch as PR

pepoipod commented 3 months ago

@miwarnec Thanks for letting me know, I will create a Pull Request as soon as possible.

miwarnec commented 1 month ago

closing thanks to https://github.com/MirrorNetworking/Mirror/pull/3864