- Home /
Mesh Position at double gameobject's position
Hello.
This is a GIF of my issue.
I have a dynamically created mesh created with the following code only once on start. The gameobject's mesh of a piece of the planet is at double the distance of the gameobject itself. The "global" and "local" positions are the same.
Turns out my issue was I had a bugged shader that was rendering the mesh in the wrong location.
Where do you get those Vector3[] points from?
Also, how often does this code being run?
Hello, thank you for the reply. I edited the question to answer your questions. Sadly, I could only really answer it with another huge block of code :/
Turns out my issue was I had a bugged shader that was rendering the mesh in the wrong location.
Please, post it as an answer and accept it if it was the cause.
Answer by rageingnonsense · Jul 14, 2017 at 06:58 PM
How are you calling CreateMesh()? what is the value of "offset"?
I am willing to bet that you are passing the position of your gameobject here, when really all the vertices are in local coordinates to the game object it is attached to. So, it is adding the global position of the gameobject to the vertices, which become local positions relative to the game object. The result is that if the gameobject is at 0,0,10, the vertices will be at local coordinates 0,0,10, which means they are at GLOBAL coordinates 0,0,20.
This is easy to test, just hardcode offset to be Vector3.zero (or remove it entirely)
Hello. Thanks for the reply. I thought this would be the problem at first too. But, the mesh is double the game object's position even when I move the gameobject in the editor without the script running again. The script is run only once, and moving the gameobject results in the mesh moving double the distance without the script having any involvement. That is why I am so confused!
In fact, I have removed the offset parameter while trying to debug this issue (it is an improvement anyways), and I still have the same bug. I don't see how this is possible!
I'm a little confused. Even if you ran the script only once (which is implied; if you were running it on update please do tell!), it would still be double the position; but are you saying as you move the object the positions gets further and further away from gameobject's global position?
$$anonymous$$aybe a gif could help demonstrate this?
You are right. $$anonymous$$oving the object in the editor moves the mesh more than the gameobject itself with the script only run once on start. As for the GIF, that is a great idea, I have edited the question and added a GIF attachment.
Your answer
![](https://koobas.hobune.stream/wayback/20220612125943im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Dymanic Mesh Hiding 2 Answers
Problems using OnRenderObject() and Graphics.DrawMeshNow() 2 Answers
Multiple Cars not working 1 Answer
Fixing mesh normals 1 Answer
Does anyone know how to change the Mesh in the SkinnedMeshRenderer? 1 Answer