how to check Vector3 and Quaternion != null?
I have a saving system and didn't have a vector and Quaternion value before.
but now I add a vector 3 and Quaternion value into the saving systems for storing my other avatar position.
So the new save file should have a new vector 3 and Quaternion value.
I need to check the vector and Quaternion != null, cause it's a struct, so it ' can't be null.
so how can I check the value is exit or not?
position != Vector3.zero , Rotation != Quaternion.identity is ok?
CodePudding user response:
Use a nullable operator and then you can check that. I'd use it as sparingly as possible so it doesn't "contaminate" the rest of your code. If you're concerned about this on deserializing then I'd keep the checks there in the deserializer and include a new bit for needsPose or something similar.
Consider
Quaternion? rotation = null;
Vector3? position = null;
Then you can deserialize if the values exist in the save file, check after deserialize, and set your needsPose bit if either is null.
I would deserialize to these nullable versions in the deserializer, set your needsPose bit in the deserialized class, and then leave the deserialized class' rotation and position variables alone. I would NOT recommend changing the class variables to nullable because then you need to add null checks everywhere you use them.