socialpoint-labs / unity-yaml-parser

Python3 library to manipulate Unity serialized files from outside the Unity Editor.
https://pypi.org/project/unityparser/
MIT License
137 stars 24 forks source link

Keep sign of negative zeros #18

Closed renattou closed 4 years ago

renattou commented 4 years ago

Just from opening and dumping prefabs that contain negative zeros like m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}, their sign is changed to m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} which results in unnecessary changes.

sp-ricard-valverde commented 4 years ago

Good finding ! I'll prepare a patch and some tests for the next release. Thanks for reporting !

renattou commented 4 years ago

Didn't expect a reply so fast! Thanks!

sp-ricard-valverde commented 4 years ago

I've prepared the changes to keep -0 values as is. But I didn't manage to get a -0 value by manipulating GameObject values from the Inspector inside Unity, it's always converted to 0.

That makes me guess that those -0 were externally written to the asset file, and keeping those in the project is not good from a Unity perspective(try to manually change a value for -0.00 for instance, and then from the Unity inspector change the value to 1 and save the project ... yeah, surprise 😛).

I think the best course of action is fixing any -0 value as this tool already does as it will fix potential issues with your Unity serialized files, and you'll have to commit the changes just once because Unity will not try to change the value back to -0.

Please correct me if I'm wrong and you have a use case that proves me otherwise and I'll be more than happy to prepare a patch.

Thanks !

renattou commented 4 years ago

I'll try to get some steps to reproduce this. In my case, even though I input 0, sometimes Unity is converting to -0 when serializing. It seems somewhat random though. And in the editor it's always shown as 0.

I normally would agree that it would be better to fix, but since I'm making a migrator that will basically go through all prefabs in my project, I didn't want to have a lot of files that changing -0 to 0 is the only change. I think it makes more sense that if I open a file and save it again using the parser without changing anything, my file wouldn't change. Especially if it's Unity's doing.

But I'll try to confirm this and I would understand if you prefer to not change this if it's not Unity's fault.