x


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?

more ▼

asked Jan 02 '12 at 02:55 PM

aoos gravatar image

aoos
1 2 2 2

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

You cannot access components in other scenes. The objects has to follow along with DontDestroyOnLoad() in that case.

more ▼

answered Jan 02 '12 at 03:01 PM

save gravatar image

save
8.2k 22 31 62

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.

Jan 02 '12 at 04:53 PM rabbitfang
(comments are locked)
10|3000 characters needed characters left

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.

more ▼

answered Jan 02 '12 at 07:40 PM

aoos gravatar image

aoos
1 2 2 2

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

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

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3740
x343
x66

asked: Jan 02 '12 at 02:55 PM

Seen: 1016 times

Last Updated: Jan 02 '12 at 07:40 PM