\$\begingroup\$

I have a load all chapters script which loads up all the Chapter items in an array and instantiates the buttons in the Viewport so you can select which chapter you would like to play. The problem is the chapters load up in the wrong order, they load up as Chapter 4, Chapter 0, Chapter 1, Chapter 2, Chapter 3. Below is the code I am using.

void Start() { menuManager = GetComponentInParent<MainMenuManager>(); levelManager = GetComponentInParent<LevelManager>(); chapterArray = Resources.LoadAll<GameObject>("Chapters").OrderBy(go => go.name).ToArray(); txtStatus.text = ""; if (chapterArray == null) { txtStatus.text = "Could not find Chapters"; return; } else { txtStatus.text = "Loading..."; FillChapterList(); } txtStatus.enabled = false; } void FillChapterList() { foreach (GameObject chapter in chapterArray) { GameObject listChapter = Instantiate(chapterListItemPrefab); listChapter.transform.SetParent(chapterListParent, false); ChapterListItem _chapterListItem = chapterListItemPrefab.GetComponent<ChapterListItem>(); chapDetails = chapter.GetComponentInChildren<ChapterDetails>(); _chapterListItem.Setup(chapDetails.chapterNumber,chapDetails.chapterName); } }

This is not only happening with the Chapter Select, it has been happening with all the arrays I load up in this fashion. Below is the visual side of the problem where you can see it loads the last object First.

I have been struggling with this for a while and I think its stopping me from progressing forward. Thank you for reading this and taking the time out of your day to help.