Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Pass data from one scene to the next

Discussion in 'Scripting' started by lz7cjc, Apr 10, 2020.

  1. lz7cjc

    lz7cjc

    Joined:
    Sep 10, 2019
    Posts:
    520
    Hi
    I have built a simple voting screen for videos in my app. However I am stuck on how to pass the video ID to the voting scene. What is the most efficient way to do this?
    thanks
     
  2. lz7cjc

    lz7cjc

    Joined:
    Sep 10, 2019
    Posts:
    520
    am going to use playerprefs unless i am told that is a really bad idea!
     
  3. SurprisedPikachu

    SurprisedPikachu

    Joined:
    Mar 12, 2020
    Posts:
    84
    There are a couple of ways.
    My preferred way is using scriptable objects.
    You can also use gameobjects that don't destroy on scene change (with DontDestroyOnLoad)
    You can also store data in static fields in classes.

    It's not a really bad idea, it's just a little bit bad idea.
    You have to use String in PlayerPrefs which is error prone and doesn't scale well. But if you're only using it one time, it's ok.
     
    lz7cjc and Alvarezmd90 like this.
  4. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    Static variables or a GameObject set to DontDestroyOnLoad are the two easiest. PlayerPrefs is for saving data between game sessions, not between scenes, though it can work.
     
  5. Alvarezmd90

    Alvarezmd90

    Joined:
    Jul 21, 2016
    Posts:
    149
    'Doesn't scale well' is bad idea when you're planning on creating a large project.
     
    lz7cjc likes this.
  6. lz7cjc

    lz7cjc

    Joined:
    Sep 10, 2019
    Posts:
    520
    thanks all