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.

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.

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 :slight_smile: