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 simonheartscake · Jan 31, 2012 at 12:39 AM · prefabvariable

Variable does not save in prefab

So I have set up a script and attached it to a rigid body, in the script i have drag and dropped a variable but when i change the whole thing into a prefab and try to instantiate it it doesn't have that variable within it, any ideas why or how to fix this. I have tried drag and dropping once a prefab and hitting apply and it doesn't help.

thanks for any advice

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

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by SisterKy · Feb 05, 2012 at 01:46 PM

By 'drag and drop a variable within it' you mean, you drag&drop an object-reference on a slot of a variable, right?
Not sure, but I dimly remember reading about this. I hope I'm not talking complete nonsense here (Half a year no unity and you forget everything oO )...
It makes kind of sense... Prefabs are meant to be able to work all the same in completely different games.
So it can't have a reference to some other part of a specific game baked into it's definition without fall-back-strategies.
That would be against its purpose.

However, you can do it differently.
You can reference the object by code and then make sure things are done with the object, only if object is actually there.
That is in accordance with how prefabs are supposed to work...

 var myRef : GameObject;
 function Start() {
   myRef = gameObject.Find("nameOfTheObject");
 }

 function Update() {
   if (myRef != null) { do something with myRef }
 }

Hrmm... there was some rule, whether you should take gameObject.Find or GameObject.Find, but I can't remember...

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 Retruate · May 27, 2016 at 03:32 AM 0
Share

Just notating, you use "GameObject.Find(GameObject exampleGo)", not "gameObject.Find(GameObject exampleGo))".

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to force a variable to prefab 1 Answer

How to stop a prefab from changing a variable 0 Answers

How do I assign a prefab to a variable with a script? 1 Answer

how to make a variable in a script that do not apply to all prefab istances 1 Answer

Accessing Variables Assigned To Prefabs 0 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