- Home /
Keep imported meshes reference in prefab
I have a Prefab with a Mesh Filter and various scripts, I also have a .blend file which Unity imports as a model (same problem with an .obj file) that I want to use in the Mesh Filter.
I take the imported mesh and drag it to the Mesh property of the Mesh Filter (or select the mesh via the asset browser). This works fine and the mesh is drawn correctly during play.
Then I end play, and start play again, and the Mesh is missing. How do I prevent this from happening?
Does any of these "various scripts" touch/modify that mesh?
I will assume you drag the mesh onto the $$anonymous$$eshFilter while you are in Edit mode, not during Play mode?
Jup, in Edit mode.
One script reads gameObject.GetComponent<$$anonymous$$eshFilter>().mesh.bounds.center... removing that read seems to fix the problem.
I can probably work around the problem that way, but I'd rather not manually enter every an offset for every pickup. Is there anyway to get the bounds without messing it up?
If you could add that as a comment I'll accept your answer :) (Why it would mess up a setting like this is beyond me though =/)
Answer by Wolfram · Jun 15, 2012 at 08:20 PM
In the comments I suggested that scripts messing with the mesh can cause such a problem.
Normaly, just reading a value such as gameObject.GetComponent().mesh.bounds.center shouldn't cause any problems, though. Which component are you requesting in that call to GetComponent()? Is that script an Editor script/has an "ExecuteInEditMode"?
If you are certain you are merely reading that value, not modifying it, you can try whether using gameObject.GetComponent().sharedMesh.bounds.center solves your problem. But note that modifying anything in sharedMesh will modify the actual Asset in your project!
Also, I forgot to ask: did you drag the mesh in to the actual Prefab that sits in your "Project" view, or did you drag it into the instance of that prefab in your scene?
I'm getting the $$anonymous$$eshFilter (had it in the comment but between less than/more than signs so it got stripped out). And I'm editing the prefab as clones are instantiated at runtime currently (had the same problem before doing that though).
And the script only runs at runtime (just after level finished loading).
Just tested it, using shared$$anonymous$$esh works without resetting the mesh, thanks!
Your answer
Follow this Question
Related Questions
Adding a new mesh to a prefab from it's blend file 0 Answers
Replacing skinned mesh prefab problem 0 Answers
Instantiate an imported blender mesh 2 Answers
Maya import. 1 Answer
How to import a mesh NOT as a Prefab 2 Answers