How to Send Variables Between Scenes in Unity

Поділитися
Вставка
  • Опубліковано 1 лис 2024

КОМЕНТАРІ • 56

  • @jw7994
    @jw7994 2 роки тому +9

    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.

  • @happym0nk3y
    @happym0nk3y 3 роки тому +3

    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.

  • @oliviad2582
    @oliviad2582 2 роки тому

    thank you i love you this helped me make a working score system that saved the score during the game over scene

  • @andrewsemenenko8826
    @andrewsemenenko8826 Рік тому

    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!

  • @thellamaamanda1246
    @thellamaamanda1246 2 роки тому +1

    DUDE you are a life saver, thank you very much. Hoping you're having a good time. Keep it going.

  • @Bonnie39
    @Bonnie39 3 роки тому +8

    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)

    • @Jourlik
      @Jourlik 2 роки тому +5

      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

    • @t3333o
      @t3333o Рік тому

      @@Jourlik thank you i love you sm

  • @NLPIsrael
    @NLPIsrael 11 місяців тому

    can you make a video on the same ussiu with netcode?... thanx for your work!

  • @boritotv6885
    @boritotv6885 2 роки тому +1

    thats exactly what i was looking for, you saved my ass

  • @loiloe77
    @loiloe77 Рік тому

    thanks bro, this was better and more performance than DontDestroyOnLoad methods.

  • @Alex-hf6zy
    @Alex-hf6zy 3 роки тому +1

    didnt realise it was that simple! Thanks for this

  • @NeleN_Games
    @NeleN_Games 3 роки тому

    i like this so much cuz finaly i understood what static is doing . ty man

  • @tunailker8
    @tunailker8 Рік тому

    Thank you so much man, I really appreciate your help!

  • @hengpisey658
    @hengpisey658 3 роки тому

    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.

  • @qqq9542
    @qqq9542 3 роки тому +1

    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?

  • @oedipascourage6262
    @oedipascourage6262 3 роки тому

    Just what I needed. Thank you so much!

  • @spectrumRoyale
    @spectrumRoyale 2 роки тому +1

    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

  • @Luvseatshawty
    @Luvseatshawty 3 роки тому +2

    Thanks for his video. Very simple and very helpful!

  • @DanNguyenQuoc-mm2ot
    @DanNguyenQuoc-mm2ot 7 місяців тому

    Supercalifragilisticexpialidocious!!! It worked

  • @bigmancozmo
    @bigmancozmo 2 роки тому

    thx i was making a battle system in my game but didn't want to make a million scenes for each battle

  • @rp88imxoimxo27
    @rp88imxoimxo27 3 роки тому +2

    What's the use to inherit StateNameController from MonoBehaviour if you dont attach it to any gameObjects?

  • @YejunYun
    @YejunYun 3 місяці тому

    THANKS A LOT

  • @taiyanglu7214
    @taiyanglu7214 Рік тому

    Thanks so much for the tip!

  • @biki_02
    @biki_02 Рік тому

    thanks a lot for this bro.❤

  • @bandoleiro431
    @bandoleiro431 2 роки тому

    Thank you so much!

  • @sajidgame1321
    @sajidgame1321 3 роки тому

    Nice video, but how about if we using playerprefs? & wich one is better? or wich one should we use?

    • @wildcockatielgames
      @wildcockatielgames  3 роки тому +6

      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.

    • @sajidgame1321
      @sajidgame1321 3 роки тому

      @@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.

  • @MichealHolt
    @MichealHolt Рік тому

    You know, I'm a little bit embarrassed I didn't think of static variables...

  • @sajidgame1321
    @sajidgame1321 3 роки тому +1

    Very nice tutorial

  • @omegaomega6838
    @omegaomega6838 2 роки тому

    Super helpful thanks

  • @BrodyBrodester
    @BrodyBrodester Рік тому

    So this is essentially global state in unity? Awesome.

    • @512Squared
      @512Squared 7 місяців тому +1

      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.

    • @BrodyBrodester
      @BrodyBrodester 7 місяців тому +1

      @@512Squared Thank you for the information. I did end up doing what you suggested. But have since migrated my project to JS/React

  • @dimitristripakis7364
    @dimitristripakis7364 3 роки тому

    These videos make me think "why do we need schools for, nowadays ?".
    Jesus the world has changed. To the BETTER !!!

  • @manavarora7644
    @manavarora7644 3 роки тому

    Thank you so much !!!!

  • @kasunlee7489
    @kasunlee7489 3 роки тому +1

    Cool. Thx man.

  • @alvintan1226
    @alvintan1226 3 роки тому +1

    Great tutorial easy to understand!

  • @sripranav
    @sripranav 3 роки тому

    We don't have to reference statenamecontroller? Im getting errors!

    • @512Squared
      @512Squared 7 місяців тому

      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.

  • @berkayylmaz2527
    @berkayylmaz2527 3 роки тому

    thx bro

  • @untemi4045
    @untemi4045 3 роки тому

    thanks

  • @WillToWinvlog
    @WillToWinvlog Рік тому

    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?

  • @zhangjiaxi9948
    @zhangjiaxi9948 3 роки тому

    nice

  • @GamePlay-dh5mb
    @GamePlay-dh5mb Рік тому

    This Is Not What The Title Said
    The Title Said Between Scenes Not Between Scripts 🤦‍♂🤦‍♂

  • @andrejrevak404
    @andrejrevak404 Рік тому

    Sorry, but you misspelled the name of this tut. Its how to send variables between SCENES, not SCRIPTS. Its another thing yknow?

  • @realkyrex
    @realkyrex Рік тому

    THERE IS NO THING LIKE STATENAME......BLABLABLA FUNCTION IN UNITY

    • @wildcockatielgames
      @wildcockatielgames  Рік тому

      4:40 - the StateNameController is a script we create in this video.

  • @Rollbaa
    @Rollbaa Рік тому

    not scalable solution if you have more data to pass from scene to scene. Little hacky just for demo purposes

    • @wildcockatielgames
      @wildcockatielgames  Рік тому +1

      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.

  • @Johan-rm6ec
    @Johan-rm6ec Рік тому

    Scripts not scenes.

  • @uchihamadara6045
    @uchihamadara6045 Рік тому

    bro SPEAK UP ICANT HEAR YOU

  • @itsWalter
    @itsWalter 2 роки тому

    thank you man, helped me a whole lot!