c# - Creating a prefab from a gameobject in scene by using Prefabutiliy.CreatePrefab -


i have gameobject in scene has children , components. want save prefab , later delete gameobject using c# scripting. have basic script handles situation :

gameobject gobject = gameobject.find(name); if (gobject != null) {     prefabutility.createprefab("assets/models/" + data + ".prefab", gobject, replaceprefaboptions.default);     destroy(gobject); } 

this code works well. saves transform components while creating prefab. mesh info of gameobject lost after createprefab operation.is there way create prefab includes components of gameobject?

you need save mesh inside prefab.

object prefab = prefabutility.createprefab(... assetdatabase.addobjecttoasset(yourmesh, prefab); destroy(gobject); 

if have multiple meshes, need addobjecttoasset each of them individually.

re: comment: there no need have functionality in build. can create gameobject @ runtime components , meshes want, clone using instantiate prefab.


Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -