• 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 /
This question was closed Sep 13, 2014 at 07:19 AM by vexe for the following reason:

Duplicate Question. Asked hundreds of times, google first!

avatar image
Question by Shnayzr · Sep 12, 2014 at 10:57 PM · c#datascenespass

How to pass data through scenes?

Hello

i have 2 scenes, Settings scene and a Gameplay scene.

in setting scene there is a sound option(on/off)

so if sound=off no sound in gameplay and viceversa

here is the sound script, the name of the script is Soundonoff

 public int soundset;
     
     void OnMouseDown()
 
     {
         if (gameObject.name == "Off")
                         
         soundset=0;
 
         else if (gameObject.name == "On")
 
         soundset=1;
     
     }


and my gameplay script (simple version)

 public Soundonoff ss;
 
 
 if (ss.soundset==0)
 
 //sound is off
 
 else if(ss.soundset==1)
 
 //sound is on



but i keep getting the error

"Object reference not set to an instance of an objet"

is there anyway to pass data through scenes?

PS:i already know about static and playerprefs so are these the only ways to pass data through scenes?

Comment

People who like this

0 Show 2
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 yoyo · Sep 13, 2014 at 06:29 AM 0
Share

You could have a static C# class (not derived from MonoBehaviour) with static properties that are initialized by a component in one scene and then can be used by a component in another scene.

avatar image vexe · Sep 13, 2014 at 07:20 AM 0
Share

A simple google gives

http://blog.christianhenschel.com/2013/05/16/how-to-pass-data-between-scenes-static-variables/

http://forum.unity3d.com/threads/global-variables-or-passing-data-between-levels.62809/

http://answers.unity3d.com/questions/532656/what-is-the-best-way-to-pass-data-between-scenes.html

http://stackoverflow.com/questions/19890538/accessing-information-between-scenes-in-unity

0 Replies

  • Sort: 

Unity Answers is in Read-Only mode

Unity Answers content will be migrated to a new Community platform and we are aiming to launch a public beta by June 9. Please note, Unity Answers is now in read-only so we can prepare for the final data migration.

For more information and updates, please read our full announcement thread in the Unity Forum.

Follow this Question

Answers Answers and Comments

27 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Transfer data between scenes + saving it C# 1 Answer

Most convenient and fast way to persist/access/modify many values from scene to scene? (C#) 0 Answers

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Not sure how to do this- destroy existing data in game obejct to prevent duplicates 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