Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by itos · Feb 07, 2017 at 04:05 PM · prefabs

I want to create individual prefabs based from Hierarchy selection.

Hi, I want to create multiple individual prefabs based from my Hierarchy game object selection. I have tried to drag and drop but I can only do it one at a time and not all at once. Since I have thousands of objects to do this I would prefer just to be able to do them all at once. I tried to find a "make prefab" button on the menu but didn't saw that option.

My task: I need to make prefabs from 1500 different FBX assets each with 12 materials. So around 18.000 prefabs would be needed in total. So what I want is to put the FBX assets on the hierarchy, put the needed material, rename it to the material color and then make a prefab batch.

Here's a screenshot of what I want to do to save time.

alt text

Basically what I need is to batch prefabs from a selection of FBX meshes with applied materials.

Thanks

03.jpg (419.3 kB)
Comment
Add comment · Show 5
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image hexagonius · Feb 07, 2017 at 09:26 PM 0
Share

why would you want thousands of prefabs.they must have something in common (white, blue) that a few should suffice

avatar image itos hexagonius · Feb 07, 2017 at 09:34 PM 0
Share

I need to make prefabs from 1500 different FBX assets each with 12 materials. So around 18.000 prefabs would be needed in total.

So what I want is to put the FBX assets on the hierarchy, put the needed material, rename it to the material color and then make a prefab batch. $$anonymous$$aybe I'm tackling this from a wrong angle?

avatar image hexagonius itos · Feb 07, 2017 at 10:07 PM 0
Share

then you need to look into editor scripting. there are ways to write prefabs programmatically, know what's selected in hierarchy, all the good stuff

Show more comments
avatar image itos · Feb 07, 2017 at 10:50 PM 0
Share

I think I was tackling the problem.

  1. Put the FBX asset meshes on the Hierarchy.

  2. Assign a material for all the meshes (select all and drag and drop the material under the component in inspector window).

  3. Use a batch rename all FBX game objects to apply a suffix for with the material name. For example: Game_Object_01_Red

  4. Drag and drop each Game Object to a Prefab folder.

  5. Copy those prefabs to another prefab folder. For example from Red to Yellow.

  6. Use batch rename tool again to rename all the new copies to Yellow: Game_Object_01_Yellow

  7. Select all the new Yellow prefab copies and apply a new colored material in the Inspector under the $$anonymous$$esh Renderer part.

Thanks to @hexagonius for making me look at the problem with a different angle.

While this solves the problem of making all 11 prefabs copies with different materials and drag and drop all over again. The original material still has to be done manually from the hierarchy using drag and drop but that's not so time-consu$$anonymous$$g. So if anyone knows a solution for that part would be great.

1 Reply

· Add your reply
  • Sort: 
avatar image
2

Answer by itos · May 14, 2017 at 12:34 AM

Doing a custom script was the better choice. This will create a new menu item with a button called Create Prefab from Selection. Just make a selection from the hierarchy, use the button and you will get prefabs made from your game object selections. Make sure to have a folder called Prefabs under the Assets folder:

 using UnityEngine;
 using System.Collections;
 using UnityEditor;
 
 public class CreatePrefab : MonoBehaviour
 {
 
     [MenuItem("Extras/Create Prefab From Selection")]
     static void DoCreatePrefab()
     {
         Transform[] transforms = Selection.transforms;
         foreach (Transform t in transforms)
         {
             GameObject prefab = PrefabUtility.CreatePrefab("Assets/Prefabs/" + t.gameObject.name + ".prefab", t.gameObject, ReplacePrefabOptions.ReplaceNameBased);
         }
     }
 }

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image glenneroo · Feb 05, 2021 at 07:09 PM 0
Share

Thanks, works great!

p.s. CreatePrefab() has been deprecated, just replace with this method instead:

 GameObject prefab = PrefabUtility.SaveAsPrefabAsset(t.gameObject, "Assets/Prefabs/" + t.gameObject.name + ".prefab");

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

64 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Accessing a certain prefab and it's children 1 Answer

Why have some of my prefabs and animations files gone blank?? 1 Answer

Spawning different items from different prefabs 2 Answers

How to make a crouch button for mobile? 2 Answers

Prefab Editor overriding locked inspector panes 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges