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. Join us on March 30, 2023, between 5 am & 1 pm EST, in the Performance Profiling Dev Blitz Day 2023 - Q&A forum and Discord where you can connect with our teams behind the Memory and CPU Profilers.
    Dismiss Notice

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,824
    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.