Search Unity

How do I call a method after loading a new scene?

Discussion in '2D' started by Raincolt, Jan 16, 2019.

  1. Raincolt

    Raincolt

    Joined:
    Jan 15, 2019
    Posts:
    13
    Code (CSharp):
    1.  
    2.     public GameObject Attribute_Controller;
    3.     public GameObject MoodImage;
    4.     public GameObject ClassesPage;
    5.  
    6. public void NewGame()
    7.     {
    8.         DontDestroyOnLoad(BackGroundMusic);
    9.         Debug.Log ("NewGame");
    10.         SceneManager.LoadScene("Story");
    11.         Skills();        
    12.  
    13. public void Skills()
    14.     {
    15.        Debug.Log("Skills");
    16.       Attribute_Controller.SetActive(true);
    17.       MoodImage.SetActive(false);
    18.       ClassesPage.SetActive(false);
    19.  
    20.         SocialTextComponent.text = "\n" + Comp + "\n" + Eleg + "\n" +
    21.             Pres + "\n\n\n" + PubS + "\n" + CMan + "\n" + Flat +
    22.             "\n\n\n" + Deco + "\n" + Inst + "\n" + Voic;      
    23.     }
    24.     }
    What I want if for after the story level is loaded runs the Skills method but it doesn't. I Get Attribute_Controller is Unassigned. It is true that Attribute_Controller is Unassigned in the previous scene but it is assigned in the "Story" Scene.

    I feel like Skills(); method should be called after the "Story" Scene is loaded but it's behaving as if it's being called while it's still in the "MainMenu" scene how do I get the Skill method to run after "Story" is loaded?
     
  2. LiterallyJeff

    LiterallyJeff

    Joined:
    Jan 21, 2015
    Posts:
    2,807
  3. qqqbbb

    qqqbbb

    Joined:
    Jan 13, 2016
    Posts:
    113
    RuntimeInitializeOnLoadMethod
     
    Olleus likes this.