Serialization of Vector3

So the documentation says:

function Serialize (ref value : Vector3, maxDelta : float = 0.00001F) : void

A guy gave an example:

stream.Serialize( ref transform.position );

but whenever I try to use this i get the following errors:

stream.Serialize(transform.position);

No appropriate version of 'UnityEngine.BitStream.Serialize' for the argument list '(UnityEngine.Vector3)' was found.

stream.Serialize(transform.position, 0.00001);

No appropriate version of 'UnityEngine.BitStream.Serialize' for the argument list '(UnityEngine.Vector3, float)' was found.

stream.Serialize(ref transform.position);

expecting ), found 'transform'.

stream.Serialize(ref transform.position, 0.00001);

expecting ), found 'transform'.

Someone please tell me what i’m doing wrong :slight_smile:

1 Answer

1

You can’t pass transform.position to the Serialize function because transorm.position is a property. Try this…

Vector3 position = transform.position;
stream.Serialize(ref position);

Thanks it worked with Vector3 position = transform.position; stream.Serialize(position); unfortunately it didn't fix the stuttering over the network at all, it stuck the player character in a small square and won't let it leave/keeps sucking it back in. Thanks for the answer, I'll have to look for a way to smooth network movement elsewhere.

Oh, yeah, with Javascript you don't have to use the ref keyword. Then again, I thought Javascript was able to deal with position being a property, but I guess not.