Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
2
Question by falantar14 · Apr 13, 2016 at 06:39 PM · unity 5networkingmultiplayer

UNet IndexOutOfRangeException: NetworkReader:ReadBytes out of range error when spawning a 2nd Player

I have a multiplayer game and when I launch the host, I can select a character and he spawns with no problem. But when I try and join the game on another (local) client, the character gets created in the scene at (0,0,0) but then I get this fatal error every time:

 IndexOutOfRangeException: NetworkReader:ReadBytes out of range: (25908) NetBuf sz:280 pos:204
 UnityEngine.Networking.NetBuffer.ReadBytes (System.Byte[] buffer, 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:302)
 SyncListItem.DeserializeItem (UnityEngine.Networking.NetworkReader reader)
 Unity.GeneratedNetworkCode._ReadStructSyncListItem_None (UnityEngine.Networking.NetworkReader reader, .SyncListItem instance)
 Player.OnDeserialize (UnityEngine.Networking.NetworkReader reader, Boolean initialState)
 UnityEngine.Networking.NetworkIdentity.OnUpdateVars (UnityEngine.Networking.NetworkReader reader, Boolean initialState) (at C:/buildslave/unity/build/Extensions/Networking/Runtime/NetworkIdentity.cs:753)
 UnityEngine.Networking.ClientScene.ApplySpawnPayload (UnityEngine.Networking.NetworkIdentity uv, Vector3 position, System.Byte[] payload, NetworkInstanceId netId, UnityEngine.GameObject newGameObject) (at C:/buildslave/unity/build/Extensions/Networking/Runtime/ClientScene.cs:478)
 UnityEngine.Networking.ClientScene.OnObjectSpawn (UnityEngine.Networking.NetworkMessage netMsg) (at C:/buildslave/unity/build/Extensions/Networking/Runtime/ClientScene.cs:533)
 UnityEngine.Networking.NetworkConnection.HandleReader (UnityEngine.Networking.NetworkReader reader, Int32 receivedSize, Int32 channelId) (at C:/buildslave/unity/build/Extensions/Networking/Runtime/NetworkConnection.cs:430)
 UnityEngine.Networking.NetworkConnection.HandleBytes (System.Byte[] buffer, Int32 receivedSize, Int32 channelId) (at C:/buildslave/unity/build/Extensions/Networking/Runtime/NetworkConnection.cs:386)
 UnityEngine.Networking.NetworkConnection.TransportRecieve (System.Byte[] bytes, Int32 numBytes, Int32 channelId) (at C:/buildslave/unity/build/Extensions/Networking/Runtime/NetworkConnection.cs:536)
 UnityEngine.Networking.NetworkClient.Update () (at C:/buildslave/unity/build/Extensions/Networking/Runtime/NetworkClient.cs:648)
 UnityEngine.Networking.NetworkClient.UpdateClients () (at C:/buildslave/unity/build/Extensions/Networking/Runtime/NetworkClient.cs:861)
 UnityEngine.Networking.NetworkIdentity.UNetStaticUpdate () (at C:/buildslave/unity/build/Extensions/Networking/Runtime/NetworkIdentity.cs:1059)

I've been trying to track down exactly where this happens but to no avail.

Note: I am using a package from the asset store that extends NetworkManager.cs

Edit: I'm also getting this error when I run the game. I'm not sure if it has anything to do with it.

 NetworkManager detected a script reload in the editor. This has caused the network to be shut down.
 UnityEngine.Networking.NetworkIdentity:UNetStaticUpdate()
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

8 Replies

· Add your reply
  • Sort: 
avatar image
5
Best Answer

Answer by falantar14 · Apr 13, 2016 at 08:21 PM

I can't imagine this is anything but a bug. I managed to fix it by overriding the OnDeserialize() method in my Player class that extends the NetworkBehaviour class.

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

And the error is no longer appearing.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image jethrogillgren · Mar 02, 2018 at 08:39 PM 0
Share

This bug is still around in 2017.3 and this fix still works, thanks.

avatar image lulle93 · Jun 04, 2019 at 01:00 AM 0
Share

THAN$$anonymous$$ YOU! I have been working on this issue for several days now.

avatar image
2

Answer by Alturis2 · Nov 21, 2016 at 01:36 PM

Hmm... I just started getting this error today and I am on 5.4.2f2

I have no OnDeserialize ( NetworkReader... ) in my project

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Jordy-Rutjens · Dec 01, 2016 at 09:00 PM 1
Share

$$anonymous$$e too, anyone got a fix for this?

avatar image camfred · Feb 02, 2017 at 09:48 PM 0
Share

$$anonymous$$e three. Still hoping somebody with know-how finds us.

avatar image MFKJ · Mar 15, 2017 at 06:09 AM 0
Share

did anyone find the solution?

avatar image Alturis2 MFKJ · Mar 15, 2017 at 01:12 PM 0
Share

For me this ended up being because I had a networked gameObject within the DontDestroyOnLoad scene. This is apparently not supported and everything must be within the active scene.

avatar image
1

Answer by suxinrenzs · Jun 20, 2017 at 06:49 AM

I was having the same problem when I read the NetworkMessage use code like this:

 CustMsg msg = netMsg.ReadMessage<CustMsg>();

Solve the problem by adding the following code in front

 netMsg.reader.SeekZero();
 CustMsg msg = netMsg.ReadMessage<CustMsg>();


Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image JonLo · Jul 03, 2017 at 11:29 AM 0
Share

Thank you so much for posting this! i have been having troubles for more than 3 months and this solved every thing, thank you!!

avatar image
1

Answer by celian29 · Jan 18, 2018 at 06:38 PM

If you have this issue, try to disable the network animator. This worked for me !

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by jough · Aug 18, 2016 at 06:40 PM

For those of you coming to this forum looking for answers...

Using 5.3.x this was a potential fix, however with 5.4 I have came to the realization that this actually causes the IndexOutOfRangeException: NetworkReader:ReadBytes error to occur.

So just to reiterate, those experiencing the issue in 5.4 should get rid of any

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

calls they may have throughout the project.

Hope this helps!

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
  • 1
  • 2
  • ›

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

108 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Unity networking tutorial? 6 Answers

Unity Network Player Classes, different models 1 Answer

can't switching between weapons in multiplayer game? 0 Answers

Re-hosting a Match in unity creates a bunch of random errors 1 Answer

Mirror multiplayer non-player object movement control options 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges