I have a GameManager that holds a list of sprites. It loads the list using Resources.LoadAll(); Then, I have and objective script that assigns those sprites to image objects.
Objective script looks like this:
public void SetObjective ()
{
int rand = (int)Random.Range (0.0f, GameManager.manager.gameItems.Length);
Debug.Log (GameManager.manager.gameItems[1].name);
this.GetComponent<Image> ().sprite = GameManager.manager.gameItems[1];
}
This exact same code works to create a grid of sprites. The debug log occurs after the NullRefernceException error, so I changed the script execution order and got the same results. What else can I try changing to get the script to run at a correct time after all of the images have been loaded?