a script works in 2017 but not in later releases

I’m playing with a triangulation utility I’ve found here.
It’s very easy to try, you basically have to define the vertices of a shape in xy format, and then a mesh is generated, it’s useful if you want some custom geometry.
I’ve found a strange behavior, if I use version 2017 the utility works fine, but with 2018 and 2019 all the fractional parts are ignored and only the integer parts of the numbers are read.
For example a vertex defined in position (2.5, 3.8) will be read as (2,3).
The question is very broad, but since the only factor that changes is the unity version, I’d like to know if there’s some very well known change among versions that explains this difference.
All the versions I tried are the latest.
Thanks
Marco

Where are you getting those numbers? Are you doing Debug.Log or what?

1 Like

Unity truncates the floats of Vector2’s and Vector3’s in their ToString() implementation by default. Make certain that’s not just what you’re seeing. Debug.Log the individual x, y, and z variables for the exact numbers, or figure out what to pass to ToString to get it to provide the actual values.

The numbers are statically set in the script, this is the section where you define the vertices

List testVertices1 = new List(6);
testVertices1.Add(new Vector2(1.5f, 0.5f));
testVertices1.Add(new Vector2(0f, 6f));
testVertices1.Add(new Vector2(3f, 5f));
testVertices1.Add(new Vector2(4f, 7f));
testVertices1.Add(new Vector2(6f, 6f));
testVertices1.Add(new Vector2(6.5f, 2f));

There’s no ToString in the scripts, and if there was version 2017 should truncate the floats the same way right?

StarManta was asking how specifically you know a Vector2 is read as (2,3) as in your cited example. Debug.Log implicitly calls ToString() on anything you pass it which isn’t a string. So ToString() not being in your code means nothing if you are still using Debug.Log to come to that determination.

For example, run this code: (throw in a Start method or anywhere you can get it to run)

Vector2 myVector = new Vector2 (1.12345f, 5.56789f);
Debug.Log("myVector: " + myVector);
Debug.Log("myVector.x: " + myVector.x + " myVector.y: " + myVector.y);;

You’ll notice that the first Debug.Log line shows different numbers than the second. The first one is truncated significantly, because Vector2.ToString() was implicitly called using the default parameters, and the default parameters for Vector2.ToString() say truncate the hell out of it. The second Debug.Log implicitly calls float.ToString(), and its default parameters says to give an accurate representation of what is stored in the float without truncation.

So again the question is, how are you determining the numbers are actually being “shortened”? Because it is not yet clear if it is actually happening, or your method of determining what if anything is happening is itself flawed.

Was this added to an existing project or a completely new project?

Ok sorry I didn’t specify that I can see it visually, if I change the coordinates of the vertices I can see that in version 2017 the resulting mesh actually changes the x position of a certain vertex (from, say, 3 to 3.5). Instead versions 2018 and 2019 only change that vertex position when passing from 3 to 4, if I set that position to 3.5 the vertex still remains at 3, I can clearly see it from the world grid.

This is a completely new blank project, it only contains that code.