Button Forgetting Gameobject on application.loadlevel

Hello I have a gamemanager that connects to a button that reset the level when clicked however when I do that the button forgets about gamemanager and I can’t reset again. Is there a way for the button to remeber the manager after an application.loadlevel?

public void Restart1 (int number){
        DontDestroyOnLoad(transform.gameObject);
        Application.LoadLevel("Level " + number);
    }

is this script on the gamemanager object or the canvas or button object?

The script is on the gamemanager object

I should have asked, but are the canvas/button children of the gamemanager? A little more code might be helpful; it’s hard to get the full grasp of what is going on here with the information given.

Also, is the EventSystem loading into the scene? Sounds like your button may be losing connection?

No its a separate object. If you mean the entire GameManager Script, here it is:

using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class GameManager : MonoBehaviour {
    private GameObject[] s1v;
    private Text obj1Text;
    //private GameObject obj1Image;
    private string lvl1Reqs;
    private string s1vls;
    private int s1vl;
    private int lvl1Req;
    public static GameManager instance = null;
    // Use this for initialization
    //Awake is always called before any Start functions
    void Awake()
    {
        //Check if instance already exists
        if (instance == null)
           
            //if not, set instance to this
            instance = this;
       
        //If instance already exists and it's not this:
        else if (instance != this)
           
            //Then destroy this. This enforces our singleton pattern, meaning there can only ever be one instance of a GameManager.
            Destroy (gameObject);
    }
    void Start () {
    }
   
    // Update is called once per frame
    void Update () {
        lvl1Req = 2;
        s1v = GameObject.FindGameObjectsWithTag("Copy");
        s1vl = s1v.Length;
        lvl1Reqs = lvl1Req.ToString ();
        s1vls = s1vl.ToString();
        //Get a reference to our image LevelImage by finding it by name.
        //obj1Image = GameObject.Find("obj1i");
       
        //Get a reference to our text LevelText's text component by finding it by name and calling GetComponent.
        obj1Text = GameObject.Find("obj1t").GetComponent<Text>();
        obj1Text.text = "Viruses Cloned: "+ s1vls + " / " + lvl1Reqs;
        if (s1vl == lvl1Req) {
            Restart1(1);
        }
    }
    public void Restart1 (int number){
        DontDestroyOnLoad(transform.gameObject);
        Application.LoadLevel("Level " + number);
    }
}

Can you verify if the EventSystem is loading on restart?

Yes it is

If that is the case, then this may be above my current knowledge level. The only other thing I can think just off the top of my head is make sure that you don’t have two game managers in the scene after the LoadLevel. Sorry I couldn’t be of more help. :frowning:

ok thanks :smile: