Script does not recognise gameObjects
Greetings & thanks for your time.
I have looked over the forums, but not seen/recognised another problem quite like mine; the issue I am having is that I have a number of public script functions, which I am connecting to UI elements and gameObjects in a relatively simple scene - this was working well enough as I was building the game, but now when I load the scene, I find that there are no objects linked to any of the scripts; when I try to re-establish the links the selector cannot identify the objects in the scene.
I had a similar problem before on an earlier project, which I solved by copy&pasting the scripts to new script objects and deleting the old ones, though since I am having the same problem again I would like to understand what is wrong and if there is a more convenient solution - especially if I end up working on larger projects where it would not be practical to redesign a scene from scratch.
PS: This issue occurs on the script prefab - when the scipts are attached to an object there is no problem. However, I want to be able to have the script prefabs callibrated so I can drop them on any object so that they are ready to go, without callibrating them every single time.
You must save the Scene from the Gameobjects to remember their stuffs and save Project so Prefabs etc remember theirs.
Answer by OncaLupe · Nov 02, 2015 at 05:26 PM
You mention is a comment that it's an issue when saving an object as a prefab, and that's the reason right there. Prefabs are just sitting in the assets and can be brought in at any time in any scene. They cannot hold references to objects in a live scene since there's no guarantee that those objects will be there when the prefab is used.
Your answer
Follow this Question
Related Questions
Is there a way to refer to the only script the object has without naming the script? 2 Answers
Breaking Object by Destroying it and Instantiating Broken Parts problem, help! 2 Answers
Novice Question: Assigning GameObject properties efficiently. 1 Answer
Checking a gameObject active in hierarchy not working. 1 Answer