Search Unity

Help Wanted Unity doesn't seem to get updates to mirror-inherited code

Discussion in 'Multiplayer' started by LoneSurvivor82, Oct 19, 2021.

  1. LoneSurvivor82

    LoneSurvivor82

    Joined:
    Aug 17, 2019
    Posts:
    35
    Hello everyone,

    I have a hard to describe problem but I will try.
    I am using Unity 2020.3.17f1 and the Mirror Networking asset for multiplayer.
    Everytime, after I have changed a minor thing in my custom NetworkRoomPlayer-class and build it to test as both host (in a virtual machine with a second Steam account) and client, I get System.IO.EndOfStreamExceptions when I'm in the room scene.

    I can solve this problem by closing Unity and delete the Library/Artifacts-folder. The reopening my project in Unity (which takes a long time!) and rebuilding. Then everything is fine. No more exceptions.

    Does this sound familiar to somebody? It can't be the solution to do this procedure for every change I do...

    Either Unity has a problem with not getting changes in files or the Mirror weaver does...

    Greetings
    Lone
     
  2. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    4,004
    Post the full stack trace please.
    We can’t see your screen from here :)
     
  3. LoneSurvivor82

    LoneSurvivor82

    Joined:
    Aug 17, 2019
    Posts:
    35
    This is the warning that is thrown:

    OnDeserialize was expected to read 45 instead of 32 bytes for object:NewRoomPlayer(Clone) component=Assets.GAME.ClassicMultiplayer.Scripts.LobbyAndRoom.NewTryNetworkRoomPlayerExt sceneId=0. Make sure that OnSerialize and OnDeserialize write/read the same amount of data in all cases.
    UnityEngine.Debug:LogWarning (object)
    Mirror.NetworkIdentity:OnDeserializeSafely (Mirror.NetworkBehaviour,Mirror.NetworkReader,bool) (at Assets/Mirror/Runtime/NetworkIdentity.cs:992)
    Mirror.NetworkIdentity:OnDeserializeAllSafely (Mirror.NetworkReader,bool) (at Assets/Mirror/Runtime/NetworkIdentity.cs:1019)
    Mirror.NetworkClient:OnEntityStateMessage (Mirror.EntityStateMessage) (at Assets/Mirror/Runtime/NetworkClient.cs:1251)
    Mirror.NetworkClient/<>c__DisplayClass46_0`1<Mirror.EntityStateMessage>:<RegisterHandler>g__HandlerWrapped|0 (Mirror.NetworkConnection,Mirror.EntityStateMessage) (at Assets/Mirror/Runtime/NetworkClient.cs:452)
    Mirror.MessagePacking/<>c__DisplayClass6_0`2<Mirror.EntityStateMessage, Mirror.NetworkConnection>:<WrapHandler>b__0 (Mirror.NetworkConnection,Mirror.NetworkReader,int) (at Assets/Mirror/Runtime/MessagePacking.cs:118)
    Mirror.NetworkClient:UnpackAndInvoke (Mirror.NetworkReader,int) (at Assets/Mirror/Runtime/NetworkClient.cs:274)
    Mirror.NetworkClient:OnTransportData (System.ArraySegment`1<byte>,int) (at Assets/Mirror/Runtime/NetworkClient.cs:342)
    Mirror.FizzySteam.NextClient/<>c__DisplayClass25_0:<CreateClient>b__2 (byte[],int) (at Assets/FizzySteamworks-Heathen/NextClient.cs:41)
    Mirror.FizzySteam.NextClient:ReceiveData () (at Assets/FizzySteamworks-Heathen/NextClient.cs:193)
    Mirror.FizzySteam.FizzySteamworks:ClientEarlyUpdate () (at Assets/FizzySteamworks-Heathen/FizzySteamworks.cs:38)
    Mirror.NetworkClient:NetworkEarlyUpdate () (at Assets/Mirror/Runtime/NetworkClient.cs:1343)
    Mirror.NetworkLoop:NetworkEarlyUpdate () (at Assets/Mirror/Runtime/NetworkLoop.cs:186)

    The error looks similar with the difference that there are also three options in the stacktrace why this would happen.
    In the meantime I found out, that Unity's AutoRefresh-option is causing that changes in the code are getting noticed but not updated in the build, so client in unity editor and host as standalone build differ. This is one of the mentioned options.

    I've already spoken to Mr. Gadget in Mirror-Discord about this phaenomenon. I can't repdroduce it within the Mirror examples.

    I documented it here and also a workaround I am using until this somehow works again like it should by default.
     
  4. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    4,004
    Notice the error message. This only happens if OnSerialize & OnDeserialize don't write/read the same amount of data. So check those.
     
  5. LoneSurvivor82

    LoneSurvivor82

    Joined:
    Aug 17, 2019
    Posts:
    35
    I have already checked them, they are uncustomized. The Problem occurs only if I use a Build without explicitely deleted the Library/Artifacts-folder or uncheck AutoRefresh in Unity and click "Reimport" on my Scripts-folder before building.

    The changes in the scripts are compiled but not updated before. The only working (around) way to not manually do this every time before build is currently using the two scripts that are invoked on pre- and postbuilding events I wrote you can find in that other post of mine here: https://forum.unity.com/threads/auto-refresh-isnt-working-properly-anymore.1186837/
     
    Last edited: Nov 1, 2021
unityunity