Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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 /
avatar image
0
Question by Timurov · Nov 14, 2012 at 03:01 PM · c#arraysceneplayerprefs

How to pass array variables from one script in one scene to another script in another scene?

I'm tried ArrayPrefs and native Unity3D PlayerPrefs both of them printed last value of the array string values. Is there a way to pass array string variables between scenes and print them all out?

The purpose of my array is getting the string variables in second scene and then somehow I need to transfer the array to the first scene and print them at least in the console, thus I can use the transferred array string values wherever I want.

Comment
Add comment
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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by paulaceccon · Nov 14, 2012 at 06:57 PM

I don't know if is this that you want, but you could use the function

 void Awake()
 {
    DontDestroyOnLoad(this);
 }

in your first scene script attached to the object A, for example, and set the vector like public (or make a get method for him). Them, in your script, attached to the object B, in scene 2, you use the GameObject.Find("A") to find the object A, that still exists, and then use the GetComponent to get its script. Them you just have to access the variable, if its public, or call the get method.

Comment
Add comment · Share
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
1

Answer by fafase · Nov 14, 2012 at 07:05 PM

What is the purpose of the array? Is it an array you are about to use all over the game in many places? You could go for a static class with a static array then.

but you better look there:

Have you seen this one? http://wiki.unity3d.com/index.php?title=ArrayPrefs

Comment
Add comment · Show 5 · Share
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 Timurov · Nov 15, 2012 at 07:46 AM 0
Share

I wrote in my question that the ArrayPrefs doesn't work for me as well as ArrayPrefs2. The purpose of my array is getting the string variables in second scene and then somehow I need to transfer the array to the first scene and print them at least in the console, thus I can use the transferred array string values wherever I want.

avatar image fafase · Nov 15, 2012 at 12:45 PM 0
Share

The other way is to use a static class to store any information you want to keep all over the game you can see there

http://unitygems.com/saving-data-1-remember-me/ http://unitygems.com/memorymanagement/

avatar image AlucardJay · Nov 15, 2012 at 12:47 PM 0
Share

fafase, link to previous question (just to let you know on the advice that has been offered so far) : http://answers.unity3d.com/questions/348063/how-to-pass-variables-from-one-object-in-one-scene.html

avatar image fafase · Nov 15, 2012 at 03:21 PM 0
Share

Is that a double post?

avatar image AlucardJay · Nov 15, 2012 at 05:25 PM 0
Share

Not sure, think the OP has a misunderstanding on how to apply ArrayPrefs or any of the other methods discussed, going by the line both of them printed last value of the array string values

It sounds like an implementation issue, maybe the OP needs a step through on populating the arrays, storing them to PlayerPrefs, on next scene loading these, and being able to step through each item in the arrays print them at least in the console.

I just gave the heads-up to save you typing stuff out that was over there.

Your answer

Hint: You can notify a user about this post by typing @username

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

Answers Answers and Comments

12 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

Related Questions

how can I improve my "character select" script? 1 Answer

Slider won't slide, issue assigning PlayerPrefs and then changing the PlayerPrefs' value 1 Answer

Deactivate game modes until tutorial is finished? 1 Answer

How Do You Have Multiple High Scores For 1 GameOverScene? 1 Answer

How to write If the player don't play the game for 24 hours, the game is over. 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