THANK YOU! Total beginner here and I was getting very frustrated. It felt like everything I tried to do ran into the issue of a script or scene not being able to access the information that it needed. This is going to make things so much easier.
Thanks for this, all of the other tutorials are the same copy paste setting of quality, resolution etc and don't handle making variables available for game objects, this is really useful.
Thank you very much ! I didn't even know how to properly express my problem to find the solution, but was ablr to find your video! Great explanation, bravo!
used this tutorial to make a basic options screen for my game, thank you! it finally works. however, i have one question: how can i make the variables carry over when the player goes back to the main menu? (check boxes and sliders have the same values as set by the player)
idk if you still need this, but if anyone reads this here's a solution. When you create a static variable and set a value, it stays through all the scenes in that class (name of the script). So basically you just create a static variable, for example "int volume" and set it with whatever number you desire in options with ui. Then you just reference "Scriptname.volume" in the game itself, it's that easy
And what about int, float and other because using static it will not allow you to change anymore so you need to manually assign it for example public static int coinsStatic; public int coins; void Start() { coinsStatic = coins; } But the problem is that how we can pass variables through scriptable object after using a singleton through other Mono behaviour scripts without attach them after scene change
Player prefs is for saving variables between game sessions. So it all depends. Say you want to set the game difficulty to hard and then have it remember that the game is set to "hard" the next time you load it up, you would store that value in player prefs. If you want to manually set the difficulty every time (like I have done here) then there is no need to use player prefs.
@@wildcockatielgames Thanks alots for you, now I understand from your nice Reply & quick Reply. Thanks again, I understood much more than before, when after your Reply.
Usually a variable belongs to an instance of the class it's declared in. So you might have multiple instances, each with its own instance ID. But this means two things, you only have one instance as such, but also that the variable belongs to the class, not to the instance, which is why you can call it without having to create and reference a specific instance of that class. But it does more than that, because if you have that variable and you do have multiple instances, then they will all use that one variable instance, they will share it across the instances, so change it in one instance and it will propagate across all the instances. It would make sense too to encapsulate that variable and thereby control access or impose constraints.
Yep. He didn't show this, but you need to attach that script to an object in each scene. That then becomes the instance used when your scene loads. Hence you can set different values like easy, medium and hard for that one value in each scene.
That's my issue with Unity. Something that should be stupidly simple. SendVariableTo(Variable, Scene). It's such an essential function how the $$#% can't this basic function be in Unity, saving us all literally hours of extra work? Are they trying to weed out beginners intentionally?
A more scalable solution would be to use a scriptable object (or several depending on the size of your game) as "settings" objects and load them up with variables that you can have anywhere with a global scope. Another would be to wrap up variables in serialized classes and pass those around. Another would be to have a scene loaded in as additive that overlays your other scenes and gives you access to those objects. These are some of the things I do to move variables around on a larger scale.
THANK YOU! Total beginner here and I was getting very frustrated. It felt like everything I tried to do ran into the issue of a script or scene not being able to access the information that it needed. This is going to make things so much easier.
Thanks for this, all of the other tutorials are the same copy paste setting of quality, resolution etc and don't handle making variables available for game objects, this is really useful.
thank you i love you this helped me make a working score system that saved the score during the game over scene
Thank you very much !
I didn't even know how to properly express my problem to find the solution, but was ablr to find your video!
Great explanation, bravo!
DUDE you are a life saver, thank you very much. Hoping you're having a good time. Keep it going.
used this tutorial to make a basic options screen for my game, thank you! it finally works.
however, i have one question: how can i make the variables carry over when the player goes back to the main menu? (check boxes and sliders have the same values as set by the player)
idk if you still need this, but if anyone reads this here's a solution. When you create a static variable and set a value, it stays through all the scenes in that class (name of the script). So basically you just create a static variable, for example "int volume" and set it with whatever number you desire in options with ui. Then you just reference "Scriptname.volume" in the game itself, it's that easy
@@Jourlik thank you i love you sm
can you make a video on the same ussiu with netcode?... thanx for your work!
thats exactly what i was looking for, you saved my ass
thanks bro, this was better and more performance than DontDestroyOnLoad methods.
didnt realise it was that simple! Thanks for this
i like this so much cuz finaly i understood what static is doing . ty man
Thank you so much man, I really appreciate your help!
thanks for this. I'm just looking for how to get user input and display in next scene but i saw your video and give me some hint.
Great video man, glad I subbed. Can I ask, can this method also be applied to collected coins shown in a level and in the main menu?
Just what I needed. Thank you so much!
And what about int, float and other because using static it will not allow you to change anymore so you need to manually assign it for example public static int coinsStatic;
public int coins;
void Start()
{
coinsStatic = coins;
}
But the problem is that how we can pass variables through scriptable object after using a singleton through other Mono behaviour scripts without attach them after scene change
Thanks for his video. Very simple and very helpful!
Supercalifragilisticexpialidocious!!! It worked
thx i was making a battle system in my game but didn't want to make a million scenes for each battle
What's the use to inherit StateNameController from MonoBehaviour if you dont attach it to any gameObjects?
THANKS A LOT
Thanks so much for the tip!
thanks a lot for this bro.❤
Thank you so much!
Nice video, but how about if we using playerprefs? & wich one is better? or wich one should we use?
Player prefs is for saving variables between game sessions. So it all depends. Say you want to set the game difficulty to hard and then have it remember that the game is set to "hard" the next time you load it up, you would store that value in player prefs. If you want to manually set the difficulty every time (like I have done here) then there is no need to use player prefs.
@@wildcockatielgames Thanks alots for you, now I understand from your nice Reply & quick Reply. Thanks again, I understood much more than before, when after your Reply.
You know, I'm a little bit embarrassed I didn't think of static variables...
Very nice tutorial
Super helpful thanks
So this is essentially global state in unity? Awesome.
Usually a variable belongs to an instance of the class it's declared in. So you might have multiple instances, each with its own instance ID. But this means two things, you only have one instance as such, but also that the variable belongs to the class, not to the instance, which is why you can call it without having to create and reference a specific instance of that class. But it does more than that, because if you have that variable and you do have multiple instances, then they will all use that one variable instance, they will share it across the instances, so change it in one instance and it will propagate across all the instances. It would make sense too to encapsulate that variable and thereby control access or impose constraints.
@@512Squared Thank you for the information. I did end up doing what you suggested. But have since migrated my project to JS/React
These videos make me think "why do we need schools for, nowadays ?".
Jesus the world has changed. To the BETTER !!!
Thank you so much !!!!
Cool. Thx man.
Great tutorial easy to understand!
wrong
We don't have to reference statenamecontroller? Im getting errors!
Yep. He didn't show this, but you need to attach that script to an object in each scene. That then becomes the instance used when your scene loads. Hence you can set different values like easy, medium and hard for that one value in each scene.
thx bro
thanks
That's my issue with Unity. Something that should be stupidly simple. SendVariableTo(Variable, Scene). It's such an essential function how the $$#% can't this basic function be in Unity, saving us all literally hours of extra work? Are they trying to weed out beginners intentionally?
U can use patterns for that event listener
nice
This Is Not What The Title Said
The Title Said Between Scenes Not Between Scripts 🤦♂🤦♂
Sorry, but you misspelled the name of this tut. Its how to send variables between SCENES, not SCRIPTS. Its another thing yknow?
THERE IS NO THING LIKE STATENAME......BLABLABLA FUNCTION IN UNITY
4:40 - the StateNameController is a script we create in this video.
not scalable solution if you have more data to pass from scene to scene. Little hacky just for demo purposes
A more scalable solution would be to use a scriptable object (or several depending on the size of your game) as "settings" objects and load them up with variables that you can have anywhere with a global scope. Another would be to wrap up variables in serialized classes and pass those around. Another would be to have a scene loaded in as additive that overlays your other scenes and gives you access to those objects. These are some of the things I do to move variables around on a larger scale.
Scripts not scenes.
bro SPEAK UP ICANT HEAR YOU
thank you man, helped me a whole lot!