- Home /
Prefab Materials and Meshes being deleted, How can I stop this
In the editor I have created prefabs (A) in a resource directory, in code I am loading them, then instantiating a copy of it(A'), and creating(instantiating) a pool (array) of gameObjects (B), finally I am setting the pool items' (B) material and mesh to that of A'.
This all works great the first time I run, but as soon as I stop, it appears that the clean up deletes (A)'s material and mesh. Why and how can I prevent this from happening to a prefab in the project?
Again Project has prefab A, I load A and instance it to A' then create B's and assign B's material/mesh to A'
Background, this is for data driven loads so I can deter$$anonymous$$e at runtime which prefab I want to create. Second I want a pool of gameobjects to draw from because I actually am loading say 3 different prefabs and when I need a gameobject I am getting one from the pool and then setting its mesh/material to one of the 3 prefabs I have loaded. This gives dynamic loading without hopefully large memory overhead.
But currently has the drawback of screwing up the actual real prefab.
example debris, i want a pool of debris gameobjects, so I create 100. But I don't want the debris to be the same display. So I load 3 gameobjects with textures of debris. Thus procedurally I deter$$anonymous$$e which of the 3 textures I need to use, and assign it to the debris pool item I have received. I should have a highwater mark for memory with the 100 pool items and the 3 differences.
(just picked numbers out for the example, I have much high numbers intended and highwater marking the memory usage is critical)
Just out of curiosity are you creating a new material when updating A's materials or simply updating the current material it uses?
Answer by theonciest · Nov 13, 2021 at 09:48 PM
such a useless system, it's been 9 years and this person doesn't get ANY freaking help.
Wonderful
The op hasn't been online for over 6 years. Also the question is extremely ambigous and it's not really clear what he actually did. So why did you bump this ancient question with an answer that does not answer the question but represents a rant? Do you consider your own actions helpful?
cassuis did ask back and did not get any reply. Also Unity has heavily changed since 2012. It has a completely different prefab system now. So even if the exact circumstances of the question had been cleared up and someone had written an answer, it would be heavily outdated by now.
I had a similar issue to this. My prefab kept deleting my mesh, and turns out the fbx itself had some issues on it. Had to reset xforms in 3ds max and collapse the stack. All is fixed, but it's stumbling across these types of threads when searching for a fix. Either there is no solution so you have to create a work around yourself, or there are dead threads like this with no answer.
My favorite are the ones where people ask for their specs, and then they reply with the specs and it is ignored for 8 years.
Your answer
Follow this Question
Related Questions
Different prefabs with same mesh but different textures(materials). 1 Answer
Apply new complex fbx to saved prefab 0 Answers
How can you duplicat folders and not share old dependencies? 1 Answer
Generated meshes/materials cannot be made into prefabs? 1 Answer
Possible Unity Glitch. A few lines of code erasing prefab data. 1 Answer