1
\$\begingroup\$

I've written a script which will automatically generate a Mesh, assign a MeshFilter, MeshRenderer, BoxCollider, and RigidBody.

This script is meant as a tool to rapidly create a certain class of objects (in this case, dice). I don't want them to actually generate at runtime.

Is there a way to convert the GameObject to a Prefab with all of its different generated properties so that I can simply drop them into my game?

Just trying to drag it into the Assets causes it to lose its Mesh. Also to note, I have it so I can generate the Mesh via the Inspector in a ContextMenu, which works well.

\$\endgroup\$
5
  • \$\begingroup\$ You should check this method from PrefabUtility's class: docs.unity3d.com/ScriptReference/… .Just take note that this is a UnityEditor's namespace class, so don't put it in a class that would be compiled in your builds or use platform dependent compilation blocks. \$\endgroup\$ Commented May 2, 2018 at 2:33
  • \$\begingroup\$ Thanks. I think I ended up figuring it out by first saving the generated mesh as an asset, then saving the object itself as a prefab. I'll check out that code though, maybe it'll have something nicer or more clever than what I'm doing. \$\endgroup\$ Commented May 2, 2018 at 2:37
  • \$\begingroup\$ @samanime please feel free to share your solution as an answer to guide future users. \$\endgroup\$ Commented May 3, 2018 at 12:07
  • \$\begingroup\$ Once I have a solid solution, I certainly will. I think I'm about 90% of the way to something I like. This is for a side project, so it'll take a bit. ;) \$\endgroup\$ Commented May 3, 2018 at 13:52
  • \$\begingroup\$ @samanime how did you save the asset? Which asset? The mesh? Or did you use something like formating it to fbx or obj? \$\endgroup\$ Commented Jul 7, 2019 at 12:27

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.