Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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
7
Question by SergeantBiscuits · Sep 21, 2012 at 06:57 AM · prefabnested

Workarounds for Nested Prefabs

Hey fellas, after raging at Unity for not updating my nested prefabs, I did the research and realized that is simply does not support them. Welp!

The game I'm working on involves many different types of vehicles (effectively an RTS), but with shared parts (turrets, wheels, etc.) My instinct from using other programs was of course to make one prefab for each kind of shared object and then stick copies of it into each appropriate unit, but that of course doesn't work out when you need to make adjustments to them.

So the best solution, it seems, is to have a 'God' class with references to all prefabs, and instantiate them via code. When a change needs to be made to a unit, I would edit the appropriate .js.

But this requires potentially having .js for every individual type of instantiated object, means of determining where it should be mounted to the parent, etc.

I'll admit my jimmies are quite rustled on this issue. No native nested prefab support seems like a huge oversight. And I am very, very hesitant to shell out $35+ on a third-party plug-in, especially with a new release of Unity coming out soon (where there are some rumors of native nested prefab support... but again, shouldn't this have been something put in place years ago?)

Or, best case scenario: I'm just missing an obvious workaround, that hopefully someone can exemplify for me? :]

Thanks as always, guys!

Comment
Add comment · Show 6
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 Shrandis · Sep 21, 2012 at 08:09 AM 0
Share

I don't understand what you're asking. Are you saying that you can't have child-parent hierarchy in a prefab? If so, that is not true.

avatar image SergeantBiscuits · Sep 21, 2012 at 09:21 AM 0
Share

No, the problem is that if you have a prefab as the child of any other object and then you make a change to the prefab in the Project, the changes will not propagate to the childed instance.

That is, objects lose the link to their prefab once they are nested. And I find that absolutely ridiculous.

avatar image SergeantBiscuits · Sep 21, 2012 at 10:35 AM 0
Share

Thanks for the input, Fattie, but I think you've missed my entire point!

Say I have a couple of different tanks (different treads and armor and such) but I want them to have the same turret. $$anonymous$$akes sense that I should make a prefab out of the turret and stick one onto each tank.

But later, I decide I want to make that turret have two barrels ins$$anonymous$$d of one. So, I pick one of the prefab turrets, add another barrel, and hit "apply"... nothing happens to the identical turrets on the other tanks. >THAT< is what I find ridiculous.

$$anonymous$$y question is, since that doesn't work, what is the community-supported method of achieving such an effect?

And hey, at least I didn't cuss! ;)

And I'm not sure what 'button' you are referring to...

avatar image vethan4 · Sep 21, 2012 at 11:04 AM 1
Share

He's talking about a turret prefab IN a tank prefab

PrefabA with prefabB inside

avatar image SergeantBiscuits · Sep 21, 2012 at 11:10 AM 1
Share

Yeah, vethan4 has it.

I have two GameObject prefabs, "PlayerTank" and "EnemyTank". I want these tanks to have the same kind of turret, so I make a new GameObject called "TankTurret" and turn it into a prefab.

Now I put an instance of the TankTurret into both the PlayerTank and EnemyTank GameObjects.

I test the game, and I decide I want to make TankTurret a little bit different. I modify one of the TankTurrets, then hit 'apply'... but nothing happens to the TankTurret in the other tank! This seems silly to me!

Show more comments

4 Replies

· Add your reply
  • Sort: 
avatar image
4
Best Answer

Answer by thienhaflash · Mar 10, 2014 at 02:22 AM

I found this one, haven't try it out but might be that's what you need : http://framebunker.com/blog/poor-mans-nested-prefabs/

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 SergeantBiscuits · Mar 31, 2014 at 06:05 PM 0
Share

This right here is gold. Thank you! Awesome solution until Unity rolls out a native functionality.

Everybody use this!

avatar image
2

Answer by vethan4 · Sep 21, 2012 at 11:16 AM

"So the best solution, it seems, is to have a 'God' class with references to all prefabs, and instantiate them via code. When a change needs to be made to a unit, I would edit the appropriate .js"

This. Have empty game object "anchors" for all the smaller prefabs and a script for each object. Each of your vehicles is gonna end up having at least 1 script attached to it anyway right? You just need to add the prefabs in at the Awake() part for each vehicle.

That's what I'd do at least in your case.

Comment
Add comment · Show 3 · 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 SergeantBiscuits · Sep 21, 2012 at 11:26 AM 0
Share

Thank you! I guess I will have to go along with this. No pain no gain I suppose, haha.

A follow-up question, if I may! In order for me to reference the prefab references in my 'God' class, I must set the variable types to 'static'. But with that, I cannot set the references in the inspector. The only way I've found to get around this is to have two variable declarations per prefab, plus an 'assignment' line:

var tankTurretPrefab : GameObject;

static var tankTurret : GameObject;

function Start(){ tankTurret = tankTurretPrefab; }

This results in three lines per variable, and these things are stacking up quick! Is there possibly a better way to deal with this?

avatar image vethan4 · Sep 21, 2012 at 11:33 AM 1
Share

One way of getting around that would be loading the prefabs from your Resources folder on a static initialize call (I'm a C# coder, so this'll look a bit different):

static GameObject tankTurret;

public static void Init() { tankTurret = (GameObject)Resources.Load("TurretPrefab",typeOf(GameObject)); }

That'll cut it down to 2 lines each?

avatar image SergeantBiscuits · Sep 22, 2012 at 05:52 AM 0
Share

That's an awesome shortcut, thanks! I will use that. Just gotta be careful not to rename my stuff. Cheers vethan4!

avatar image
-1

Answer by Bento-Studio · Mar 19, 2014 at 08:17 PM

Why not check out our plugin "nested prefab" from Bento here: http://u3d.as/content/bento-studio/nested-prefab/2Jz

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 Lordloss · Jun 06, 2016 at 12:57 PM 1
Share

Because $$$...

avatar image
0

Answer by PrefabEvolution · Mar 28, 2014 at 07:48 AM

Also another solution of Prefab Nesting http://forum.unity3d.com/threads/236719-Prefab-Evolution-Plugin

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 Lordloss · Jun 06, 2016 at 01:03 PM 1
Share

Again, because $$$. Stop your advertisements. Stop making bucks out of the situation we suffer from a basic function missing in unity.

Unity: Gives away nearly any mighty function for free. You: $$anonymous$$aking money out of our problems.

This sucks.

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

16 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

Related Questions

Instantiating a prefab in the editor is orphaning the children of the prefabs 0 Answers

Prefab variant changing all other variants. 1 Answer

Nested Prefabs in Asset Bundle 1 Answer

Are nested prefabs officially supported in unity 4.6+ at last? 1 Answer

"The prefab you want to instantiate is null" what am I doing wrong nested...? 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