My game starts playing music before the unity player progress meter is even finished. Is there a way to know when everything is done loading before the game does anything?
you cannot know. even if the level finished loading you could have a bunch of scripts that pool objects, instantiate gameObjects, or other intensive tasks. depending on the computer or device's power, these tasks will finish at different rates.
I say cheat. play the music on a coroutine that waits for a second or two, or as long as your safely need. that way you know the level will be finished loading and things will get going before the music starts...
I'm quite certain that this delay is actually due to the GUI delay that I asked about in this other question: http://answers.unity3d.com/questions/46508/unitygui-display-delay
Never had such a behaviour. What player do you talk about? Standalone or webplayer? If you build a webplayer do you use the "streamed" option? Because with a streamed web build unity starts playing after the first level is streamed. You have to check yourself if everything is loaded via Application.GetStreamProgressForLevel.
Where do you start your music? Just an audiosource with a looped audioclip? How long before (the progressbar disappears) do you hear the music? Some more information on your setup could be helpful.
edit
If you use ExecuteInEditMode and you want to start the sound in the Start() method, just check for Application.isPlaying. It’s always true for all kinds of builds, but inside the Editor it’s just true when in PlayMode
.
I would recomend you to set up a loading state in your first scene where you wait for level loading and other async processes that needs to be done before you create your object that plays music.
If you load your level with
Application.LoadLevel();
you need to wait until
Application.isLoadingLevel
is false before you start your music
Are you starting the music in Awake() (PlayOnAwake)?
If so, maybe you should try doing that in Start() instead? Awake is called when the object is created and Start is called before the first frame is executed. Thus the object might start playing while its loading. Having it in Start might allow for the game to fully load before it is called.
void Start()
{
audio.Play();
}
Since this is the first link that comes up when you google the issue, if anybody ever stumbles upon this while searching for a solution, you can start a coroutine, have it wait for 0.1 sec and then play your music. This somehow forces it to wait before everything is loaded and then starts the coroutine. I am no expert, I am unable to explain this, but it worked for me.
AsyncOperation asyncLoadLevel;
IEnumerator AddLevel (){
asyncLoadLevel = SceneManager.LoadSceneAsync("MyLevel", LoadSceneMode.Additive);
while (!asyncLoadLevel.isDone) yield return null;
}