Checking if all Materials are generated?

Hello! :slight_smile:

My problem is just not knowing if this line of code exists, I can’t find it anywhere. Here is the situation:

In my game, I use some nice Materials, and they take a while to generate on slower computers (one of which being my own). I counted the seconds it took for the Materials to generate when I loaded a new scene (20 seconds), and I decided to make a loading screen. What crossed my mind though is the possibility of someone playing the game with a slower computer than my own. This would mean the Materials would take more than 20 seconds, so when the loading screen disappeared, Materials would still be loading.

In order to make a universal script for a loading screen, I would need a line of code that checks if all the Materials have been generated. This way, the loading screen would finish at the correct timing.

Thanks in advance to anyone who knows how to fix my problem! :wink:

Bump.

Are you using the ProceduralMaterial class for this? If so you can check the isProcessing property of each material.
To check all materials in the scene you could try something like:

IEnumerator WaitForMaterials()
{
	object[] materials = Object.FindObjectsOfType(typeof(ProceduralMaterial));
	
	while (true)
	{	
		bool ready = true;
		foreach (ProceduralMaterial material in materials)
		{
			if (material.isProcessing)
			{
				ready = false;
				break;
			}
		}
		
		if (ready)
		{
			yield break;
		}
		else
		{
			yield return null;
		}
	}
}

Then in your loading screen code:

	yield return StartCoroutine(WaitForMaterials())
	// Code to stop loading screen