- Home /
Switching meshes
Hello,
In my game I made a button that toggles when it's stepped on and it works fine. Then I made the button change the mesh (mesh filter) to a different mesh for when it is toggled and not toggled. Now when I run the game it starts to lag after a few minutes and then it freezes so I have to force quit it! I've tired clearing the mesh, recalculating the bounds, recalculating the normals, but nothing seems to have an effect. When I comment out that part of the script it works again.
Here's the code:
if(!isToggled){
if(GetComponent(MeshFilter).mesh != T)
GetComponent(MeshFilter).mesh.Clear();
GetComponent(MeshFilter).mesh = T;
GetComponent(MeshFilter).mesh.RecalculateBounds();
GetComponent(MeshFilter).mesh.RecalculateNormals();
}else{
if(GetComponent(MeshFilter).mesh != notT)
GetComponent(MeshFilter).mesh.Clear();
GetComponent(MeshFilter).mesh = notT;
GetComponent(MeshFilter).mesh.RecalculateBounds();
GetComponent(MeshFilter).mesh.RecalculateNormals();
}
}
If anyone knows what I'm missing, any help would be greatly appreciated!
Thanks!
Because I couldn't find a solution I've also posted this problem on the forum.
Someone said that I should make tow child objects that get turned on and off but I can't make 2 child objects since the script is applied on the button itself, not on a parent.
Putting the script on an empty game object and then making the graphics objects as child objects isn't an option since I don't have a prefab for the buttons, so I would need to make these adjustments to dozens of buttons. Since the buttons are connected to about 10-15 doors, 50-180 pickups, 3-10 turntables... in each level I would need to adjust and re-connect all of them and re-write almost 500 lines of code. Normally I wouldn't care, but at the moment I don't have enough time to make these adjustments.
I hope someone has another idea how this problem can be fixed.
Thanks!
Are you running that code in the Update, every frame? edit I've just seen that you do, here
Code posted here: http://forum.unity3d.com/threads/switching-meshes.253892/#post-1683250
Answer by varie-tea · Aug 17, 2014 at 10:32 PM
If someone else has a similar problem: The answer was given here in the forum. Thanks.
Your answer
Follow this Question
Related Questions
Mesh information explained. 1 Answer
Materials on an imported mesh 1 Answer
How can I change the lookout of an object? 0 Answers
Mesh between lines - Mesh.SetIndices 1 Answer
Can you store arbitrary data in a Mesh? 2 Answers