Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 jacobjones · Oct 30, 2015 at 09:06 PM · prefabinspector

Prefab loses associations in Resources folder

I rewrote my question: Object A needs to access the script on Object B. So in Object A's script I make a public variable for Object B and its script. After this I drag and drop Object B and its script into the appropriate spots in the Inspector for Object A. When I run it, it works fine. When I then put the Object A in the resources folder, the places in the inspector associated to Object B go blank. So I drag and drop them again, this time from prefab to prefab and it looks like it will work, but it doesn't. One difference I notice is that when I do it the first way, the associations are bold and in the prefab they are not.

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 OncaLupe · Oct 31, 2015 at 09:07 AM 0
Share

$$anonymous$$y answer still applies to your question after the re-write. You can not link between objects saved as an asset and get them to work in a scene. The references point to a specific version of an object, so when you drag a reference from A to B in Resources, they still point to those resource versions after being put in scene. You need to get the references during runtime after they're instantiated.

As for the entries being bold, that points out a difference between a scene version of an asset and the prefab version.

2 Replies

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

Answer by OncaLupe · Oct 30, 2015 at 09:42 PM

References only work between objects within a scene, or on the same object when saved as an asset. You can't link between two asset objects.

Think of this example; If you could link in the assets and have 'a' pointing to 'b'. You then drag 'a' and two 'b' objects into the scene. Which 'b' should 'a' actually point to?

To do what you want(guessing you need these created during runtime), you'll need the objects searching the scene for the other object(slow but fairly simple), or use a third manager object to hold references. For instance you can have a GameController object that stays in the scene at all times, which has variables for 'a' and 'b'. When you instantiate 'a' or 'b', they set their respective values in the GameController and grab the value for the other object if it's set.

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 Bunny83 · Oct 31, 2015 at 04:20 PM 0
Share

You can't link between two asset objects

This is a bit misleading. You can "link" between assets just fine. Of course if you instantiate a prefab the "link" / reference to another asset still points to the asset and not to some instance in the scene.

The question is a bit ambiguous what kind of "object" is ment. I guess the objects are objects in the scene and he linked them in the scene. When he dragged object A into the resources folder he actually created a prefab of the object A instance. Prefabs / assets can't reference objects in the scene so of course the reference to object B in the scene is removed in the prefab.

Then it seems that he also created a prefab out of object B and assigned the prefab of B to the variable in prefab A.

It's not really clear why he actually created prefabs out of the objects and if there are still instances of those prefabs in the scene or if they are instantiated at runtime.

Fact is scene objects are like in a nested scope of the project. So things in the scene can reference other things in the scene or things in the project (assets / prefabs). However assets / prefabs can't reference anything that is inside a scene.

An analogy could be a class and the methods inside that class. A class variable can be accessed from anywhere inside the class. However a local variable inside a method can only be used inside that method. The class would represent your whole project while the method(s) represent your scene(s). It might makes more sense if you consider that a scene doesn t have to be loaded all the time. If you switch from sceneA to sceneB all things inside sceneA are no longer available. Assets however don't belong to a scene. They are always available.

avatar image
0

Answer by jacobjones · Nov 01, 2015 at 01:35 PM

Yes, now I understand. I was associating prefabs, instead of having the prefab's script look in the hierarchy with GameObject.Find("objectname").GetComponent(scriptname);

Thank you so much for the help.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

prefab contents of the Custom inspector disappear. 0 Answers

Prefab not inheriting GameObject when instantiated 1 Answer

Change material inside instanced prefab, gameobject.renderer is NULL 1 Answer

What is the name of/How do I use the box in the Script Inspector that allows you to assign values to Public data? 2 Answers

Semi-Quick question about "LookAt" script after respawn. 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