Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
0
Question by gord0 · Oct 27, 2011 at 02:15 PM · instantiateprefabchild

prefab question

I have a model of a gun. I've brought it into unity and added some components and then made it a prefab.

There are scenarios in which I only want to instantiate one of it's children.

Is it possible to instantiate just one child of a prefab or will i need to make a whole bunch of separate prefabs for each piece?

Screen shot showing the prefab with it's children expanded: http://www.gordonjennings.net/temp/C14prefab.PNG

Comment
Add comment · Show 4
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 oxium · Oct 27, 2011 at 02:32 PM 0
Share

I guess if the child is also a prefab you should be able to do that..

avatar image gord0 · Oct 27, 2011 at 02:46 PM 0
Share

I mean. For example the prefab shown in the screen shot is called "C14a". I can instantiate that and BA$$anonymous$$! I have the whole gun. But it won't let me instantiate the children of the prefab on their own. For example if I want to instantiate the Scope by itself, I have to make a new prefab of just the scope. Is there some special syntax I could use to instantiate children of prefabs? So that I don't need to go through this whole thing and make a new prefab for each piece.

avatar image oxium · Oct 27, 2011 at 04:07 PM 0
Share

oh that.. yeah I don't think you can.. or I have no idea how..

I would in this case have some prefab A, B, C .. then have another master prefab (for example ABC using the 3 other prefabs..)

hoping that makes sense ;-)

avatar image gord0 · Oct 27, 2011 at 04:16 PM 0
Share

well basically this is for an application that allows people to assemble/disassemble weapons with rules enforced so they have to follow a sequence. So for example you can't remove the cheek plate until you remove the cheek plate screws.

One of the features I've implemented is that there is a second camera that is placed in the upper left corner on top of the main camera view. When the user clicks on any piece that piece becomes highlighted (scripting manipulates material colors to give a glow effect). The highlighted piece gets cloned and placed in front of the second camera so it appears in the upper left of the screen. Info about the piece is displayed and the user can rotate the piece in the smaller window. As shown in this screen shot: http://gordonjennings.net/temp/highlightWindowExample.PNG

The problem is that some pieces have geometry such that the program will freeze briefly when it's being instantiated. I figured prefabs would speed up the instantiation in contrast to clones.

The reason I wanted to do what my original post suggested is so I don't have to make prefabs for all the pieces and just reference the main prefab.

Oh well, unless anyone comes up with an idea, I'll have to do just that :(

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by DaveA · Oct 27, 2011 at 03:33 PM

I suppose you could instantiate the whole thing, then turn off or delete the parts you don't need. But you might also be able to create a new object using AddComponent(Mesh) and so forth to build an object from mesh and materials. Not really clean either way. You could also write an Editor script which could dissect your models and build all those sub-prefabs for you.

Vote for nested prefabs at feedback.unity3d.com

Comment
Add comment · Show 2 · 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 RetepTrun · Oct 27, 2011 at 04:13 PM 0
Share

That sounds good, 1st unparent what you want and then delete the unwanted.

But really I would just make more prefabs.

avatar image gord0 · Oct 27, 2011 at 06:56 PM 0
Share

well good news guys. Before exploring what I was trying to do, I had no idea there were editor scripts. So i made one to quickly make prefabs out of all the children of the main prefab. The parts load instantaneously when clicked on now : ]

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Instantiate the subchild (the renderer) from prefab? 1 Answer

Prefab - Child of GameObject. 0 Answers

Prefab, procedural attachment of child, childCount return 0 1 Answer

Instantiated child doesn't move along with the parent in case of low frame rates 0 Answers

Make a simple tree 1 Answer


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