Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question DontDestroyOnLoad doesn't read itself

Discussion in 'Getting Started' started by di-pretoro, Oct 13, 2022.

  1. di-pretoro

    di-pretoro

    Joined:
    Aug 8, 2015
    Posts:
    4
    hi to all, i have an issue passing data trough scenes: in the 1 scene i pass a value nameTatticToLoad to LoadDataManager, then i call a scene and i want that LoadDataManager will do some staff and i think i did the right tinks
    The problem is that in the new scene in the ispector i see the value nameTatticToLoad in LoadDataManager, but if i Debug.Log("nameTatticToLoad: " + nameTatticToLoad) i get nameTatticToLoad is empty.
    this is the code:
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class LoadDataManager : MonoBehaviour
    6. {
    7.     private static LoadDataManager dataManagerInstance;
    8.     public static LoadDataManager current;
    9.  
    10.     public string nameTatticToLoad;
    11.     private void Awake()
    12.     {
    13.         current = this;
    14.         DontDestroyOnLoad(gameObject);
    15.         if (dataManagerInstance == null)
    16.         {
    17.             dataManagerInstance = this;
    18.            
    19.         }
    20.         else
    21.         {
    22.             DestroyObject(gameObject);
    23.         }
    24.     }
    25.     public void passNameTattic()
    26.     {
    27.         Debug.Log("Call passNameTattic");
    28.         Debug.Log("nameTatticToLoad: " + nameTatticToLoad);
    29.         if (this.nameTatticToLoad != "")
    30.         {
    31.         Debug.Log("nameTatticToLoadENTERRRR");
    32.         UIManager.current.fileName = nameTatticToLoad;
    33.         UIManager.current.LoadMove();
    34.         UIManager.current.PlayAction();
    35.         }
    36.     }
    37. }
    38.  
    i don't understand why i never see the Debug.Log("nameTatticToLoadENTERRRR") like this.nameTatticToLoad != "" is alway false also if i see the value in the ispector
    thz for help
     
  2. saermuk

    saermuk

    Joined:
    Aug 10, 2020
    Posts:
    13
    Are the scripts in other objects?
     
  3. di-pretoro

    di-pretoro

    Joined:
    Aug 8, 2015
    Posts:
    4
    yes, they'r in other objects.