3 Replies - 1173 Views - Last Post: 23 August 2015 - 04:25 AM Rate Topic: -----

#1 DJ2334  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 17
  • Joined: 08-February 13

Unity: Accessing a script from another script in another scene

Posted 21 August 2015 - 04:40 PM

I've been having a lot of trouble with this. I've attached Script A to Object A in Scene A and I want to access Script A in Script B attached to Object B in Scene B. And yes, I've used DontDestroyonload. It works, but I keep getting null errors because when I try to attach Script A to Script B in the inspector, Script A isn't there. Note: Script A has Boolean values that I wish to be read by Script B.

I'm trying to make a game which involves choices and after you make a choice, you go to the next scene, but you can go back to the previous scene to change your choice. I want the choices to be saved somewhere, so at the end all the choices you picked will be displayed. Can someone help me out here? I know my question is a bit vague, but if someone can help me with my first problem then that would be helpful. I've heard a lot about PlayerPrefs, but it seems a little confusing. I'm not sure I want to go that route right now. I'd rather just stick with the Don'tDestroyonload method for now if I can.

This post has been edited by modi123_1: 22 August 2015 - 09:42 AM
Reason for edit:: fixed title


Is This A Good Question/Topic? 1
  • +

Replies To: Unity: Accessing a script from another script in another scene

#2 andrewsw  Icon User is offline

  • say what now
  • member icon

Reputation: 6410
  • View blog
  • Posts: 25,910
  • Joined: 12-December 12

Re: Unity: Accessing a script from another script in another scene

Posted 22 August 2015 - 02:33 AM

Sounds like an XY Problem, but really it is about asking Smart Questions.

Please provide a clear question. In particular you should start by explaining which gaming platform you are using, or what type of application.
Was This Post Helpful? 1
  • +
  • -

#3 BBeck  Icon User is offline

  • Here to help.
  • member icon


Reputation: 792
  • View blog
  • Posts: 1,886
  • Joined: 24-April 12

Re: Unity: Accessing a script from another script in another scene

Posted 23 August 2015 - 03:55 AM

So let me start out by saying "I don't know the answer". I only have maybe 6 months of Unity experience at the most and I stopped doing it about a year ago.

That being said, I think the answer is to have a "Game Manager" object that calls everything else from a "Game Manager" scene.

I think this video kind of demonstrates this.

My understanding of how it works is that you are basically calling one game object from another game object in another scene.

This might be helpful too.
Was This Post Helpful? 0
  • +
  • -

#4 stayscrisp  Icon User is offline

  • フカユ
  • member icon

Reputation: 1040
  • View blog
  • Posts: 4,325
  • Joined: 14-February 08

Re: Unity: Accessing a script from another script in another scene

Posted 23 August 2015 - 04:25 AM

You might want to look into using a ScriptableObject instead of attaching something to the scene especially if you want to keep something between scenes.

http://docs.unity3d....ableObject.html

ScrptableObjects are basically the go to for any object that is only meant to store data.

https://unity3d.com/...iptable-objects
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1