- Home /
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.
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.
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
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.
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/
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
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
Follow this Question
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