• 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 code-blep · Sep 19, 2012 at 12:17 PM · gameobjectprefabs

Prefeabs do not remember Inspector selected GameObjects. Why?

Hi,

I have some prefabs that have a number of attached scripts. These require to know the location of a GameObject, and I was using the inspector to select the required GameObject. For example:

var target : GameObject;

When the prefab is placed into the Scene, I can drag and drop the required GameObject onto the script no problem. However I cannot apply the selection to the prefab. Also I can drag the GameObject into the prefab in my resources folder.

Is this normal behaviour as it seems counter intuitive to me?

If it is normal behaviour, am I best to refer to my target GameObject using the find GameObject, etc commands, or is there a more efficient way to do this?

I ask as I dread to think how much typing would have to be done if I changed the name of the target component / gameobject etc.

All words of wisdom welcome!

Thanks

Paul

Comment
Add comment · Show 1
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 Khada · Sep 19, 2012 at 12:43 PM 0
Share

If you set your gameobject references as the default values on a script, it should remember them. To see what I mean, look at the inspector with a script selected.

1 Reply

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

Answer by Lockstep · Sep 19, 2012 at 12:31 PM

If the prefab would remember an object from the scene, the prefab would be limited to only this scene. Even if you had another instance of your target in another scene it would be a different gameobject. Thus prefabs will only remember other prefabs as used for instantiating i.e..

I'd suggest to use Find/FindWithTag once during start. That is not more than a line of code. Just make sure your target has a unique name/tag. Also don't use those functions every frame since they are expensive.

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 code-blep · Sep 20, 2012 at 12:09 PM 0
Share

Hi again Lockstep ;)

Pretty much as I thought. I was just wondering if there were any other reasons. I'll mark this as the answer ;)

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

11 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

Related Questions

Create with code 2.2 pizza not shooting 1 Answer

how to get the prefab path of a game object in Game mode,not Editor mode 1 Answer

Prefab doesn't keep it's public variable when Instantiated? 2 Answers

Getting MouseEnter to Another Object 1 Answer

Mark gameobject field as changed from prefab 2 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