How to Transfer Data Between Scenes in Unity (Simple)

Поділитися
Вставка
  • Опубліковано 4 вер 2024
  • How to Transfer Data Between Scenes in Unity (Simple)
    Greetings, in this quick Unity tutorial we shall be looking at how to transfer data between scenes. This can be handy for all sorts of situations, like settings, remembering the state of something, health and so much more.
    For transfering the value of a variable from one scene to another, we will be using a static variable to achieve this. Static variables are useful when you want to share data or maintain a common state between different parts of your game or program. They allow you to avoid duplicating information and help you manage and coordinate actions across various objects.
    A static variable in Unity is a variable that belongs to a class rather than to instances or objects of that class. It is declared with the keyword "static" and is shared among all instances of the class.
    When a variable is declared as static, it means that there is only one copy of that variable, regardless of how many objects or instances of the class are created. This single copy of the variable is accessible by all instances of the class, allowing them to share and access the same data.
    Thanks for watching this quick and simple tutorial on how to transfer data between scenes using Unity and C#.
    Subscribe to keep notified when I upload: tinyurl.com/Su...
    How to Transfer Data Between Scenes in Unity (Simple)

КОМЕНТАРІ • 20

  • @prinolangovender4094
    @prinolangovender4094 5 місяців тому +2

    Worked for me, thanks for the tutorial👍

  • @PersikTheK
    @PersikTheK 5 місяців тому +2

    Thanks! The coolest tutorial😀

  • @NaveenJharsa
    @NaveenJharsa 2 місяці тому

    Task: Replicate the two scenes shown in the reference videos using any preferred game
    engine (Unity, Cocos Creator, Unreal Engine, etc.):
    ● Assignment 1 - Video Reference
    ● Assignment 2 - Video Reference
    Enhance the visual appeal of the scene with creative use of shaders or particle effects.
    Please tell me how do this ?

    • @maxodidily
      @maxodidily  2 місяці тому

      What are the video references?

  • @shazeerrra
    @shazeerrra 4 місяці тому +2

    instead of text, how can i transfer image gameObject to other scene and also when i click the button, i dont want it to load to other scene but instead just save/transfer the image gameObject to the other scene.

    • @ciaodar2457
      @ciaodar2457 2 місяці тому

      yoooo! you probably figured it out after a month but, literally the ONLY thing you should do is change static variable to Image class. set the static reference as the Image instance you want. video uses string as an example but you can use ANY type. go br

  • @emidic3187
    @emidic3187 4 місяці тому

    thanks you saved our asses for an assignement lol

    • @maxodidily
      @maxodidily  4 місяці тому +1

      With the amount of asses I am saving, I should become a butt doctor. Glad this video helped!

  • @Trenton2G
    @Trenton2G 11 місяців тому +1

    Upon switching scenes the game object being stored in the data is instantly lost and becomes "Missing (GameObject)" no part of the code is altering the data, something is losing in on scene switch and chat GPT can't even find a solution so it's not the code it's something with the scenes. Is there something I'm not understanding about data management?

  • @risingforce9648
    @risingforce9648 8 місяців тому

    this is only work for two scnee? is not modular ? I need to keep Text ..not data....

    • @maxodidily
      @maxodidily  8 місяців тому

      What do you mean by text? Are you referring to a text object on a UI canvas?

    • @risingforce9648
      @risingforce9648 8 місяців тому

      @@maxodidily yes , you can store the data in persistent data, let say a different class ... but at the end of the scene , to load new scene or other scene you alawyas need a TextUI component to load before the scene start...in that situation you can load the current component reference (text) to the script. but separate the component from singleton's requirements.

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

    Max is no beta,
    Sharing data,
    Across game mode.
    Jump the scene,
    Variable clean,
    Public int load!

  • @user-sb3xz3tn2q
    @user-sb3xz3tn2q 8 місяців тому

    How to Transfer two Data Between Scenes?same text data,(help me bro)

    • @maxodidily
      @maxodidily  8 місяців тому

      What do you mean by same text data?

  • @czubai
    @czubai День тому

    I found this pretty much impossible to follow with you almost screaming at me. Just a bit of feedback from the misophonic or whatever folk.

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

    didn't work

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

      Could you provide more details please?

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

      I'm just too much of a newb and I guess I needed to hear it explained differently. I managed to get it to work eventually with a different method. Thanks for the reply though! I am a fan of when youtubers care :) @@maxodidily

    • @maxodidily
      @maxodidily  11 місяців тому +1

      No worries and glad to hear it is now working for you!