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 Tiktaalik · Sep 17, 2013 at 06:08 PM · prefabscenelinkingprefab connection

Linking a prefab to another prefab in deep hierarchy using Inspector

I'm trying to figure out how to have some UI Screen Panels link to one another. I'm considering each screen to be a prefab, and then I've created a script that attaches on a button that will connect a screen to another screen. In this way the user will be able to advance through screens.

The problem I'm finding is that when I drag these Panels into the scene, the prefab loses this reference. I've taken a screen shot below to indicate an example of the bolded reference (UIButton Flow Panel at the bottom right) that gets lost when the prefab enters the scene.

I suspect there is some issue with linking from deep in the object hierarchy.

I found this rather ancient forum post that suggests that such prefab-to-prefab linking only works at the top level of the hierarchy, not deep like I've done here. I've tested that and it seems to work. Is that really the only solution?

I want to be clear here. I don't want prefabs to link to objects in the scene. I know that that doesn't work. I want to have a prefabs link to other prefabs so that I can organize how they're connected at the prefab level, and instantiate them or drag them to the scene at some other time.

alt text

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 ZenithCode · Sep 17, 2013 at 06:15 PM 0
Share

Nested prefabs are not yet supported by Unity.

avatar image Tiktaalik · Sep 17, 2013 at 06:18 PM 0
Share

From my understanding I don't think I'm talking about Nesting prefabs. Nothing in the "PopupPanel" hierarchy for example is a prefab. I'm talking about having a child object of one prefab "PopupPanel" have a script that has a reference or link to another prefab "HackPanel."

avatar image ZenithCode · Sep 17, 2013 at 06:25 PM 0
Share

O$$anonymous$$ yes you can. So in your script create a variable with the type of your object.

$$anonymous$$g. public BulletType bulletType;

where 'BulletType' is the class name.

If you have a prefab with the BulletType script on it, then you can drag that onto this variable field.

Note: $$anonymous$$ake sure that in your code you always instantiate an instance of this object before you modify any of its properties as doing that means you're modifying the prefab properties not the instance.

avatar image Tiktaalik · Sep 17, 2013 at 06:28 PM 0
Share

I've gotten that simple case to work, but not this deep hierarchy case. I'm going to edit the question to emphasize that it's not working in this deep hierarchy situation.

avatar image ZenithCode · Sep 17, 2013 at 06:35 PM 0
Share

O$$anonymous$$ I don't think you can get that behavior that deep in the hierarchy.

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by DaveA · Sep 17, 2013 at 06:53 PM

" I'm talking about having a child object of one prefab "PopupPanel" have a script that has a reference or link to another prefab "HackPanel."

Your child object would have a script on it which has something like

var hackPanel : GameObject;

And you can set that via the inspector. It should be like any other variable on any other component: that it will have a default value (null in this case), and instances can override that in the Inspector or with code. You would drag from the Project pane the prefab you want onto this instance's hackPanel field.

Which looks like what you have done, right? And what's not working with that?

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 Tiktaalik · Sep 17, 2013 at 08:04 PM 0
Share

While instances of a prefab can have references to each other, you see$$anonymous$$gly can't have a prefab reference a prefab at that deep level of hierarchy. Looking at it now it simply seems to be an authoring issue. Unity won't display anything below one level for prefabs so it's impossible to author prefab to prefab connections.

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

17 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

Related Questions

Connecting scenes 3 Answers

How to find a prefab in another scene? 1 Answer

Preventing first instance of object from starting on screen 1 Answer

getting prefabs form project to another 3 Answers

Can I change a prefab without changing the scene? 3 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