0
\$\begingroup\$

I have an older Unity Unet Game which I build 2 or 3 years ago and forgot about it. Now I wanted to show it to a friend but it does not work anymore. When I start the server as player1 in the editor I can see that player2 can join and no errors (using runtime build) occur in the console but player2 can't play, he seems stuck but I can see him in the hierarchy of the editor.

When I start the server as player1 in the runtime and try to join with player2 in the editor I can see that player2 has a playercontroller-id of -1 a network-id of 0 and also a scene-id of 0.

Is that because Unet is EoL or should it work and I just missed something?

I am using the old version 2018.3.0f2.

I can still see the other player and can kill him but the other player simply seems to not take over the main camera. I have to investigate a bit further.

In the editor I got this error message:

IndexOutOfRangeException: NetworkReader:ReadBytes out of range: (21440) NetBuf sz:41 pos:5
UnityEngine.Networking.NetBuffer.ReadBytes (System.Byte[] buffer, System.UInt32 count) (at C:/buildslave/unity/build/Extensions/Networking/Runtime/NetworkBuffer.cs:45)
UnityEngine.Networking.NetworkReader.ReadString () (at C:/buildslave/unity/build/Extensions/Networking/Runtime/NetworkReader.cs:305)
Player_Controller.OnDeserialize (UnityEngine.Networking.NetworkReader reader, System.Boolean initialState) (at <811655ab22fa4c9c9e92117581e47a9e>:0)
UnityEngine.Networking.NetworkIdentity.OnUpdateVars (UnityEngine.Networking.NetworkReader reader, System.Boolean initialState, UnityEngine.Networking.NetworkMessage netMsg) (at C:/buildslave/unity/build/Extensions/Networking/Runtime/NetworkIdentity.cs:745)
UnityEngine.Networking.ClientScene.ApplySpawnPayload (UnityEngine.Networking.NetworkIdentity uv, UnityEngine.Vector3 position, System.Byte[] payload, UnityEngine.Networking.NetworkInstanceId netId, UnityEngine.GameObject newGameObject, UnityEngine.Networking.NetworkMessage netMsg) (at C:/buildslave/unity/build/Extensions/Networking/Runtime/ClientScene.cs:499)
UnityEngine.Networking.ClientScene.OnObjectSpawn (UnityEngine.Networking.NetworkMessage netMsg) (at C:/buildslave/unity/build/Extensions/Networking/Runtime/ClientScene.cs:560)
UnityEngine.Networking.NetworkConnection.HandleReader (UnityEngine.Networking.NetworkReader reader, System.Int32 receivedSize, System.Int32 channelId) (at C:/buildslave/unity/build/Extensions/Networking/Runtime/NetworkConnection.cs:469)
UnityEngine.Networking.NetworkConnection.HandleBytes (System.Byte[] buffer, System.Int32 receivedSize, System.Int32 channelId) (at C:/buildslave/unity/build/Extensions/Networking/Runtime/NetworkConnection.cs:425)
UnityEngine.Networking.NetworkConnection.TransportReceive (System.Byte[] bytes, System.Int32 numBytes, System.Int32 channelId) (at C:/buildslave/unity/build/Extensions/Networking/Runtime/NetworkConnection.cs:576)
UnityEngine.Networking.NetworkClient.Update () (at C:/buildslave/unity/build/Extensions/Networking/Runtime/NetworkClient.cs:754)
UnityEngine.Networking.NetworkClient.UpdateClients () (at C:/buildslave/unity/build/Extensions/Networking/Runtime/NetworkClient.cs:966)
UnityEngine.Networking.NetworkIdentity.UNetStaticUpdate () (at C:/buildslave/unity/build/Extensions/Networking/Runtime/NetworkIdentity.cs:1086)

Maybe you can explain what that error message says?

I kind of fixed it by adding the following method to my networkbehavior

 public override void OnDeserialize(NetworkReader reader, bool initialState)
 {
     base.OnDeserialize(reader, initialState);
 }

But now lots of other bugs occur, when I kill my opponent points are not assigned and so on. Does this happen because of deprecated Unet or am I just too dumb?

I built the game using version 2018.3.11f1 which seems to have some differences to 2018.3.0f2. Using the correct minor version did the trick. I wonder that much has changed between these 2 minor change releases.

\$\endgroup\$
1
  • \$\begingroup\$ The norm on Stack is to not signal edits (i.e. adding "Edit:" to edited text). The edit history is available for anyone who wishes to see prior versions of the post. \$\endgroup\$
    – Pikalek
    Commented Dec 18, 2022 at 17:49

1 Answer 1

0
\$\begingroup\$

IndexOutOfRangeException: NetworkReader:ReadBytes out of range: (21440) NetBuf sz:41 pos:5

Look like you're sending/receiving a byte array of which you do not know the size of nor you check things. Also I don't believe you're using exception handling.

Treat all data as if it is wrong or invalid and use exception handling. These exception are barely mentioned anywhere but self-respecting developers (professionals and amatures) as wel self-respecting-code will be using exception handling very often.

Exception handling:

try
{

    // Receive data.
    // Process data.
    // Whatever.

} catch(Exception e )
{

    // Give feedback or simply ignore any catched errors.

} finally
{

    // Code what has to be executed to tie up things.
    // Not per se needed.

}

Deprecated code is code one should not use anymore, still it is valid for backwards compatability.

Another thing comming to mind is did you change one (or more) systems in the meanwhile. There is this thingy of little and big endian, messing up your data big time.

With the information you have given, nothing else can be said without guessing. It can be just one little thing to resolve every thing. Make a back up of the original one with the initial error so you can revert when messing up big time in your bug diving adventure.

\$\endgroup\$
1
  • \$\begingroup\$ I was using the correct major but the wrong minor version of unity. Thank you anyway \$\endgroup\$
    – MBrain
    Commented Dec 19, 2022 at 9:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .