PunLookSource throws Error: you cannot read this stream that you are writing!

arenoo

Member
I've spent the whole day trying to figure out why my multiplayer setup suddenly stopped working. I have a very similar setup to the demo and at first it was working as expected, but now after some seemingly unrelated changes as soon as I connect the second client to the room I get an error in PunLookSource and the whole game breaks (first screenshot). I tried to add a check for stream.IsWriting but it started throwing another error (Index out of range) on the master client (second screenshot). Also in rare cases (about 1 in 10 chance) when I connect the second client to the room everything works as it should and this makes it even harder to understand whats going on. I am thinking maybe some network related execution order inconsistency? Any ideas?
1721747661139.png
1721748103103.png
 
That is strange and unfortunately I haven't seen that happen before. There is a IsWriting check which should only allow the component to read from. If you revert does it work? This may be a question for the PUN developers.
 
I've figured it out. In the demo SpawnManagerBase class the player instantiation is happening in OnPlayerEnteredRoom but sometimes when the scene that is being loaded is heavy or the device/connection is slow the instantiation photon event is sent from master before the client finishes loading and ends up missing the event entirely. I've fixed it by "requesting" a spawn from the loading client through a photon event instead of automatically spawning it in OnPlayerEnteredRoom. This way the client will request a spawn when it has finished loading and is ready to receive events.

I have no clue how nobody had this issue before me, seems like it should have never worked consistently for anyone right?

As for the errors, I did not figure out the exact cause, but it was related to scene loading/execution order issues.
 
Last edited:
Back
Top