Search Unity

Question How to make an gameObject refered across scenes?

Discussion in 'Multiplayer' started by Explor, May 31, 2020.

  1. Explor

    Explor

    Joined:
    Apr 19, 2020
    Posts:
    1
    I make an online game which has two scenes, one is the login scene and the other is the main game scene. And I want to use an game object which serves as an network component which keeps the login states and other network related data.
    The problem is that how can I make this game object get refered in the both scenes since after the user login, the main scene needs to use the scripts attached to the game object. How can I do it? I need you help, thanks!
     
  2. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    There's a few options. The easiest is just to grab a reference to the object as soon as the next scene loads. Just give the object its own unique tag and find it by that tag. You'd set the object to DontDestroyOnLoad so it isn't destroyed when the previous scene unloads.