JSON.stringfy breaking change Vector3

I was checking out the beta to see if my current app would need to be modified. I noticed one thing that was broken. In 4.1, JSON.stringify(<vector3>) would return {"x":0,"y":12,"z":32} however in the latest build it returns {"_isDirty":true,"_x":0,"_y":12,"_z":32}

Here is a playground so you don’t have to type it out.

Will this be the version going forward?

1 Like

Yes, I think this change has been done to improve performances of Vector3 in some circonstances.

@Deltakosh will know better.

1 Like

We did that to be able to cache vector3 value so yes this is the going forward state :wink:

There is always Vector3.toString() but I dont know if that helps you.

It’s no problem, I just had to change how I read the value back in to use _x instead of x, it was just an unexpected issue when updating.

Thanks!

3 Likes

i would always use an array in such cases, [ xVal , yVal , zVal ] will never change :slight_smile:

1 Like

Yea, that’d be the best bet, to just serialize it myself as some interface, but since it just worked as is in the past, I left it alone.

I’m just stuck with the same problem. It’s very uncomfortable when you do serialization and back. While Vector3/Quaternion converts to a string like this:

"position": {"_isDirty":false,"_x":2,"_y":0,"_z":0},
"rotation": { "_isDirty":false,"_x":0.7071067811865475,"_y":0,"_z":0,"_w":0.7071067811865476},
"scale":{"_isDirty":false,"_x":1.0546875,"_y":1.0546875,"_z":0.1 }

it’s very uncomfortable when you get such structure after simlpy calling JSON.stringify(). When you store such data in JSON files there is some overhead. So seems I will simply replace replace strings:

'"_isDirty":false,' --> "" 
'_x" ->- "x" 

but there will be some pain if the format of Vector3 sometime will change to same other.

And as far as I understand from explanation above it’s better not to redeclare toString() prototype for Vector3 :smile: