- Home /
Mesh Disappears simply by mentioning it in a script
Quickest way to produce the problem in c#:
using UnityEngine;
using System.Collections;
public class asdf : MonoBehaviour
{
public GameObject thing;
void Start()
{
Debug.Log (thing.GetComponent<MeshFilter>().mesh); //Look at your debug window in unity
}
}
REMEMBER to name it asdf.cs AND to assign the script a model AND to place the script on a model.
The problem: play the game. Now quit it. The mesh disappears from mesh filter.
REMEMBER to reimport the model to test again.
Important Details: Hit play after reimporting, and click on your model inside the project panel. In the inspector, scroll down where you see the tab "Imported Object" and look at the mesh filter, the mesh has became "Type misMatch".
I tried my best make this as detailed yet short as possible, if you request that I get more information please tell me. (and how, if needed , since I'm a beginner)
EDIT: I am using Mac OSX 10.6.8 and I am using Unity version 3.5.2f2.
Sounds like should be a bug report. I assume you have tried $$anonymous$$eshFilter meshFilter = thing.GetComponent\<$$anonymous$$eshFilter\>(); Debug.Log(meshFilter.mesh); which may give different results. Not really sure what mesh 'to string' will do.....
I will look into it more later, but I found that one could cheaply hack by adding the mesh as a public variable, and assigning it to the model. thing.GetComponent<$$anonymous$$eshFilter>().mesh = publicmesh;
What a very weird problem, I might have to bug report it if the things you said gave the same result.
The fact that the compiler doesn't complain about the "Type mis$$anonymous$$atch" scares me.
EDIT: gosh, just merely mentioning the string makes it lose the mesh. Looks like I might have to report a bug.
1) What type mismatch? 2) I followed your steps and the mesh does not disappear.
Could be an issue special to my computer. I am using $$anonymous$$ac OSX 10.6.8, But if there's anything more I could say let me know.
If it produced the bug, where it would say the name of the mesh with a circle on the right (like cube or plane), it would turn into "Type mis$$anonymous$$atch"
Answer by Ribboninju · Jun 25, 2012 at 09:08 PM
SOLUTION: create a public Mesh of that model and assign it to the model.
SCRIPT:
using UnityEngine;
using System.Collections;
public class asdf : MonoBehaviour
{
public GameObject thing;
public Mesh thingy;
void Start()
{
Debug.Log (thing);
Debug.Log (thingy);
thing.GetComponent<MeshFilter>().mesh = thingy;
}
}
Now you can never lose the mesh, however this is more of a workaround of a bug that should be reported than a solution.
So, have you reported this bug? I faced the same thing on Windows 7 using Unity 4.2.2. I guess it's still there, unsolved.
Answer by SantiMuffin · Aug 10, 2012 at 08:42 PM
I got this same problem. Couldn't figure out the why, but found a different work around. If you are not going to be modifying the mesh you can use something like.
MeshFilter mapMesh = gameObject.GetComponent<MeshFilter>();
Debug.Log(mapMesh.sharedMesh);
With the sharedMesh you are calling the actual Mesh(mother) and not the instantiated shape(daughter).
Just remember that if you modify this sharedMesh all of the objects that use it will be modified as well. Check the documentation for more info :)
Your answer
![](https://koobas.hobune.stream/wayback/20220613073252im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Finding flat, horizontal regions for reliable object placement? 0 Answers
Is it possible to make vertices defined by a mesh and mesh filters animating? 0 Answers
How to prevent editor to set the scene dirty if a script changes a mesh (@ExecuteInEditMode) 1 Answer
Generate a highpoly sphere with mesh collider procedurally 2 Answers
Mesh Filters randomly self deleted 0 Answers