|
When importing a mesh, I want to automatically create a prefab for that mesh, and assign that mesh to the new prefab. I have something like this:
But I don't know how to add the mesh to the prefab. In the editor, I can drag-and-drop it in the project window. How do I do this programmatically?
(comments are locked)
|
|
This is a snippet from the code I use to create prefabs from a group of selected objects:
You may want to try with EditorUtility.ReplacePrefab, althought caveat emptor: I've only used it at editor time, not in the asset post-processor.
(comments are locked)
|
|
Use CreateEmptyPrefab to prepare your prefab asset. Then construct your desired GameObject as you would like it to be ingame. Finally use ReplacePrefab to store your GameObject in your prefab and Destroy the original GameObject if you don't want it in the scene. Thansk. You also answered the next question I was about to ask, which was "I want to put my FBX mesh into another empty GameObject and create a prefab out of that, so that my prefab doesn't have an X rotation of 270."... it's not completely obvious you have to instantiate it in the scene then destroy it. Thanks!
Dec 06 '09 at 01:31 AM
Lance Sun
(comments are locked)
|
|
You can use ReplacePrefabOptions = ReplaceNameBased without destroying scene object problem. OMG dude, you just made my day...I have been working on a Editor Extension to let me update Prefabs automatically, and although I had it working the way I (almost) wanted, I was having a problem with the Prefabs getting deleted and re-instantiated again, which would move them all back to the Prefab's default position/rotation...I have been going nuts for the past 3 hours trying to figure this out, and then your post finally made sense to me and I saw a big bright light :) A BIG THANK YOU lol
Aug 06 '12 at 06:11 AM
ronronmx
(comments are locked)
|
|
Use Prefab in your Game Here is the tutorial for that . http://lnkd.in/J6ufVr . Here is demo and code for Prefab instantiate so download and try to undestand i hope u will get the solution ..
(comments are locked)
|
|
You should now be using PrefabUtility, not EditorUtility for all prefab operations. Not only does it have a method for creating empty prefabs but it also has a method to create prefabs from existing GameObjects:
(comments are locked)
|
