Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 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
1
Question by Seith · Jun 20, 2014 at 06:54 AM · prefabgame objectroot

How do I find a gameObject's prefab parent?

Hello, I have a gameobject in my scene which is a deep child of an instantiated prefab. And I would like to know how to determine its prefab root/parent (in the scene) without having to resort to iterating up from parent to parent while comparing strings (which strikes me as very clumsy).

Obviously I cannot use transform.root since that would get me the topmost parent object, which could itself be a parent of my child object's prefab, not the prefab itself.

Oh and that should be at runtime too, so I can't use any editor function.

Since that sounds like a very simple thing I'm sure it's possible but I haven't found a way yet. Could anyone help please?

Comment
Add comment
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

2 Replies

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

Answer by tswalk · Jun 20, 2014 at 07:13 AM

Perhaps you just need to add a component that stores that originating gameobject as a reference on its' instantiation. If you happen to know ahead of time which gameobject child is in the parents hierarchy....

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 Seith · Jun 20, 2014 at 08:18 AM 1
Share

Thank you, that would work of course. I was hoping for a more official (as in "built-in") solution for something so basic but since there doesn't seem to be any way to do that in Unity I'll go ahead and accept the answer... :)

avatar image tswalk · Jun 20, 2014 at 05:43 PM 0
Share

I can relate.. there is a lot to be done when talking about game runtimes. I too am working on similar things, and finding it is a must to create different "state" managers for things I could easily handle in the editor (like via prefabutiliyy.xxx), but seems to be the nature of the how things are done here.

avatar image
0

Answer by donnyjang · Jan 14 at 10:35 AM

I know this answer isn't directly related to the original question but I was trying figure out what the parent prefab was for a prefab variant in the editor itself and google took me here. Afterwards I figured it out so I thought I'd post my findings here just in case someone else does the same thing I did.


If you open the child prefab (As if you were going to edit the prefab) and then in the inspector, click the override dropdown in the top right. From there you should be able to see the parent prefab at the top as shown in the screenshot. If this isn't showing up for you it's possible that this was a feature added in a later version. I am running version 2020.3.25f1

alt text


2022-01-13-16-23-26.png (88.2 kB)
Comment
Add comment · 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

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

24 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

Related Questions

How do I change a game object prefab tree to allow it to move in the wind? 1 Answer

Game Object seems empty after instantiation 1 Answer

Prefab of a prefab? 4 Answers

Physics.RayCast problem with instantiated prefab 0 Answers

Can not Get the Children of Prefab? 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