How to convert string to vector in c#?

Helloo!

I’m saving vector data into a text file. Rather than save out each coordinate item by item, I figured I could save out each vector instead… like,

sw.WriteLine (transform.position);

The resulting text file is cool, it’s in the form of:

(3.0, 10.1, -84.1)
(3.0, 10.1, -84.1)

etc…

Problem I have is how to translate this back into a Vector3 when it comes in as a line, since System.Convert (of course) doesn’t have a vector type.

Anybody got any ideas on how to go about this? Do I need to parse the string into x,y,z and re-construct the vector with the resulting float conversions?

Thanks in advance for help :slight_smile:

Jeff.

Yes…actually you should do that for output too, or else you’re limited to one decimal point of precision. Unless that’s all you care about, of course (or maybe there’s some way to change that?). Careful about different methods of representing floats in different locales; there’s some topics around here about that.

–Eric

Thanks, Eric. Good point!

I split it up to get it working, but wondered if there was another way that I was missing!

Thanks again for helping me out :slight_smile: