- Home /
How to find a script from another Scene?
Hi! i'm trying to get the component script from another scene that's currently calls it but it keeps returning NullReferenceException
MenuScript modeScript;
modeScript = GameObject.Find("GuiNode").GetComponent<MenuScript>();
I'm trying to access the menuScript that is attached to the GuiNode Gameobject but as i said it belongs to a diffent scene from the one that calls it. Can you help?
Answer by save · Jan 02, 2012 at 03:01 PM
You cannot access components in other scenes. The objects has to follow along with DontDestroyOnLoad() in that case.
I will add on to this by saying: the reason you can't access gameobjects/components/scripts/etc. that only exist in other scenes is because the object/whatever is not even loaded in memory. From the engine's point of view, the thing doesn't even exist.
Answer by aoos · Jan 02, 2012 at 07:40 PM
Thank you for your answers! The reason why i want this, is because my first scene is used as a menu to choose between 1 player or 2 players in order to get a boolean value in the second scene about this choice.
Your answer
![](https://koobas.hobune.stream/wayback/20220613062613im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
A node in a childnode? 1 Answer
How do you add levels to your game? 1 Answer
Fps Aiming Script help 2 Answers
Need a "square tire" script. HELP! 1 Answer
Show Strings With Last Characters of the first Word 1 Answer