OnSerialize / OnDeserialize help, IndexOutOfRangeException: NetworkReader:ReadByte

public override bool OnSerialize(NetworkWriter writer, bool initialState)
{
if (this.syncVarDirtyBits == 0 && initialState == false)
{
return false;
}
else
{
writer.Write(this.transform.position);
return true;
}
}
public override void OnDeserialize(NetworkReader reader, bool initialState)
{
realPos = reader.ReadVector3();
dist = Vector3.Distance(this.transform.position, realPos);
}

results in:

IndexOutOfRangeException: NetworkReader:ReadByte out of range:NetBuf sz:16 pos:16

Any idea why?

dunno what you doing, but first, remove this:
if (this.syncVarDirtyBits == 0 && initialState == false)
{
return false;
}

the packet is never sent if the dirty is 0, and I think you shouldn’t ever return false on it?

I though the docs said returning false means do not send anything.

I see, it seems it does set the dirtybits to 0.

Are you sure you don’t have any syncvar variables?

So it seems like returning false does send a packet with no data and no way to detect that it is useless.

I am still on 5.6.2, does anyone know if this is a fixed bug, open bug or intended behaviour.

Wait, do you have more than one script that inherits from networkbehaviour on that object?

Because it is a known bug that if any of them send a packet, all of them will send one, even if it will be empty.

I am inheriting from a class that inherits network behavior but the middle class does not overload Serialize/Deserialize

uh, that wasn’t what I asked

Ok, now I understand what you meant.
Yes there were multiple network behaviours on the game object so that is the cause.
Is this one of the never going to be fixed bugs I just need to work around?

Yes, I think the workaround is either sending your own dirtypacket or never returning false on it.

You can find a fix here: Mirror - Open Source Networking for Unity - Community Showcases - Unity Discussions
Also provides you with proper error logging to see what exactly went wrong.