I have created a script that build a mesh which represents the fluid based on collider objects in the scene.To detect if this fluid touches anything i have to convert these mesh vertices to Polygoncollider so this way it would be able to detect 2d components when it collides but i have come across with an interesting problem.The problem is when a pull the vertices data and import it in the polygoncollider by using SetPath my fluid mesh object disappears at sometimes(in some frames).I check if it was a problem that environment based but its not here the things that i know about the problem
but first to clear things the objects which i have in my scene
- A game object that contains the mesh data
- A game object that contains polygonCollider component (apart from the mesh object)
- A gama object that contains my script which i use this script to create mesh and polygoncollider object seperately
Lets come to the things i know about the problem
- Problem disappears when i delete the line which holds to pass vertices to polygonCollider
- If i run the code my mesh appears and disappears like randomly
- I freezed to scene and checked the polygoncollider and when i checked the points array it was the same positions 1-360 all of them was the same.
- The identical positions was irrevelant from the actual positions, the positions when objects appears without a problem
And here my code part that runs the line that i pass mesh vertices to polygoncollider
Triangulator _tr = new Triangulator (_collection);
Mesh _mesh = new Mesh();
_mesh.name = "MeshVolume";
_mesh.vertices = Roveldo.convertDimension (_collection);
_mesh.triangles = _tr.Triangulate();
//_mesh.uv = _collection;
_mesh.RecalculateBounds();
_mesh.RecalculateNormals ();
_obj.GetComponent<MeshFilter> ().mesh = _mesh;
border.GetComponent<PolygonCollider2D>().SetPath(0,_collection); // THE PROBLEM
*** If you dont have a clue to solve this would you help me with these things below ?***
- If there is a way to detect meshcollider with 2d collider components.
- If there is a better way to achive this other than colliders.