Same script working yesterday not working today
Hello, I made a script that makes a list of the childs of an object and then sets them active one at a time using a coroutine. The script is suscribed to an event on another script's Start function for testing reasons. It worked perfectly yesterday, but today after opening the project again and pressing play, it didn't work :S could be something to do with the event? or the coroutine?
public class FootPrintManager : MonoBehaviour {
public delegate void FootstepsShot();
public static event FootstepsShot FootstepsEnd;
public float delayTime = 1.0f;
public List<GameObject> footsteps;
void OnEnable(){
AnimController.ShotLight += StartSteps;
}
void OnDisable(){
AnimController.ShotLight -= StartSteps;
}
public void StartSteps(){
foreach(GameObject step in footsteps){
StartCoroutine("Walking");
}
}
void Start () {
footsteps = new List<GameObject>();
foreach(Transform steps in transform){
footsteps.Add(steps.gameObject);
}
}
IEnumerator Walking(){
foreach(GameObject step in footsteps){
yield return new WaitForSeconds(delayTime);
step.SetActive(true);
}
}
}
Thanks!
Answer by $$anonymous$$ · May 13, 2016 at 07:09 AM
The order of the two scripts is important in your case. The Start function in one script must start before the other one starts. Unfortunately the order can be random and can be different on different platforms and devices. You can however define an order to specific scripts with Edit-->Project settings --> Script execution order. Add your script that has to be executed first and give it a negative number to be sure it starts first.
unfortunately this didn't work, but thanks a lot for that info I didn't know. I'll keep finding what may be the problem. A difficult thing to do because I tested the game just before closing the project and going out of work, and it worked good, then the next day it didn't, I moved nothing in between...
Answer by Rodolinc · May 13, 2016 at 02:41 PM
I just found out what it was, maybe I was lucky the first time I ran the script it filled the list of gameobjects "before" I was reading it in the StartSteps function. The solution was to change my Start() function to an Awake() function and now the List gets filled before trying to access it.
Your answer
![](https://koobas.hobune.stream/wayback/20220612080700im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Performance of event vs static method call 0 Answers
Coroutines not running one after another 1 Answer
Error with calling events from other scripts 3 Answers
Continuously monitor childrens properties 1 Answer
How would i modify my current script to remove these UI buttons without killing my pause menu? 1 Answer