- Home /
Meshfilter missing on Instantiation of prefab for Hex creation
I am attempting to create hex tiles, each as their own gameobject (eventually to fill an array). If I take a gameobject with the appropriate mesh properties and make an instance of it in the editor with an appropriate script to calculate and draw the hex at start, I get a rendered hex. My meshfilter in the gameobject is empty initially but on program start it creates a mesh and assigns it correctly so that I have the meshfilter attribute occupied. However, when I take a prefab of my hex gameobject I get some very odd results trying to instantiate it. I have a main gameobject which has a script with a public var to which I link my prefab. I can successfully instantiate the prefab but when I call the function to render the hex it does not occupy the meshfilter. To add to the confusion, if I instantiate and call the function in update it repeatedly spawns gameobjects (as I would expect) but each of them aside from the first has the meshfilter occupied and renders appropriately. I tried instantiating in awake and calling the function to render in start but no good. If I just repeat the instantiation and call twice in start I get two gameobjects, one with an empty meshfilter and one correctly filled. Thoughts on how I can instantiate just a single gameobject with a correctly filled meshfilter?
Turns out that the resolution is somewhat counter-intuitive. I was instantiatiing then calling the function but when I swapped it and called the function before instantiating...voila. Still sort of puzzled since I would assume a gameobject could change the filter once it was instantiated but perhaps the answer to that is found elsewhere.
Your answer
![](https://koobas.hobune.stream/wayback/20220612054619im_/https://answers.unity.com/themes/thub/images/avi.jpg)