Nothing being called after coroutine.

The following coroutine runs and successfully adds image files to a List. However, no methods are called after running the coroutine.

void Start()
    {
        CreateMap(10, 10);
        SetTexturePaths();
        GetFileNamesFromPaths();
        StartCoroutine(GetTextures());

        DisplayGameTileTextures();
    }
IEnumerator GetTextures()  // Coroutine.
    {
        foreach(string fileName in _gameTileTexturesFileNames)
        {
            string filePath = _gameTileTexturesPath + fileName;
            Debug.Log("filePath: " + filePath);
            Byte[] byteFile = File.ReadAllBytes(filePath);
            Tex = new Texture2D(256, 256);
            yield return Tex.LoadImage(byteFile);
            Tex.Apply();
            _gameTileTextures.Add(Tex);
        }
        yield break;
    }

Do I need to somehow stop the coroutine? Or is it a different issue?

Eh… I had to convert the next method called to a coroutine also in order for it to be called only after the first one stopped.

If you want DisplayGameTileTextures to be called after the GetTextures returns, you need to make the Start method a coroutine and yield until the GetTextures function completes.

IEnumerator Start ()
{
    yield return StartCoroutine (GetTextures ());
    DisplayGameTileTextures;
}
1 Like