"Start" function running multiple times - why?

Hi,

I have a single empty object, Update Manager, with a single script attached, also named Update Manager.

It has an Awake function that does work, just a few bits like this for the most part:

LevelManager = GameObject.Find("LevelManager");
        LevelManagerScript = LevelManager.GetComponent<LevelManager>();

The Start() function is also straightforward:

void Start() {
        CompanyManager = new CompanyManager();
        //set Tick length and timer details
        tickLength = 1000; // in nanoseconds
        if(tickLength < 1000) //if tickLength is too short, then set TurnBased to true and proceed
        {
            isTurnBased = true;
            activateUI(EndTurnCanvasGroup);
        } else
        {
            timer = new System.Timers.Timer();
            timer.Interval = tickLength;
            timer.Elapsed += new ElapsedEventHandler(OnTick);
            timer.Enabled = true;
        }

    }

My problem is that this extremely simple object with what seems like extremely simple code attached is somehow instantiated 3 times, despite only existing once.

What could have gone wrong? What should I start testing?

How do you know that it’s run 3 times? Use Debug.Log and check each Start instance for its source object.

2 Likes

[DisallowMultipleComponent] above your MonoBehaviour class will guarantee that it is added to the same GameObject only once. Without seeing what code attaches this script, it is impossible to explain why the component is added several times.