❔ I'm trying to convert a Vector3 string to a Vector3 but the numbers returned aren't correct.
8 Replies
For instance, I'll have the string
"1"
and everything appears to be fine with the debug messages but when it's used in the actual vector3 = new Vector3(StringToConvert[0], StringToConvert[0], StringToConvert[0]);
it changes to the numbers 49
.49 is the ascii code for the character '1'.
You can't use it directly as the number it represents. You know it's a 1, but your computer doesn't treat it that way.
I see you are already using
Parse
but then you use the chars from the original string to construct your vector which won't work.The string methods you're using do not affect
StringToConvert
, they return an object which you're not saving to a variable.
Currently what vector3 = new Vector3(StringToConvert[0], StringToConvert[1], StringToConvert[2]);
is doing is vector3 = new Vector3('0', '.', '5');
which should likely be evident in your debug logs.
For example, StringToConvert.Split(',');
will return you a string array which needs to be saved to a string[]
variable. Alternatively just chain the methods and save it into a float[]
variable.
Also your LINQ is going to throw an error because you need to be parsing part
as opposed to the initial string.linq methods have no side effects so they only return the result
Thank you all for your help in understanding the issue. I believe I have found a solution by using
looks good to me, don't forget to $close if there are no more questions
Use the
/close
command to mark a forum thread as answeredWas this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.