Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
4
Question by Gillissie · Mar 11, 2011 at 06:50 PM · loadingeventstreaming

How to wait until everything is loaded before starting?

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?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

7 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Gillissie · Mar 23, 2011 at 06:41 AM

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

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
1

Answer by loopyllama · Mar 11, 2011 at 08:01 PM

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...

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image eelstork · Nov 02, 2015 at 08:25 AM 0
Share

If somebody have a bunch of scripts doing this and that THEY can know that they do.

avatar image
0

Answer by Bunny83 · Mar 11, 2011 at 07:07 PM

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.

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Gillissie · Mar 14, 2011 at 05:15 PM 0
Share

Web player. The Audio Source is in the scene and set to "Play on Awake". It usually starts playing 1-2 seconds before I actually see my scene.

If I uncheck "Play on Awake" and start the sound in the Start() method of my main script, then the sound plays a bunch of times in the editor because I have @script ExecuteInEdit$$anonymous$$ode() enabled for my GUI stuff. I suppose I could split the script, but it's such a hassle for scripts to talk to each other because you have to set up all the object references. $$anonymous$$aybe there's a best practices doc for Unity scripting?

avatar image Bunny83 · Mar 14, 2011 at 06:15 PM 0
Share

Take a look at Application.isPlaying. I've changed my answer.

avatar image Gillissie · Mar 14, 2011 at 07:15 PM 0
Share

Thanks for the tip. I tried that but it still starts playing music before anything is displayed. There is a 1-2 second delay between the unity progress meter and actually seeing something (screen is plain white during this time), but the music starts immediately. I have a feeling it's something I'll just have to live with.

avatar image rainyy · Mar 26, 2011 at 03:30 AM 0
Share

Have you ever fixed the problem? The same thing is happening to me

avatar image
0

Answer by Niklas · Mar 11, 2011 at 07:43 PM

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

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Ashkan_gc · Mar 11, 2011 at 07:48 PM 0
Share

he said that music starts before progress bar finishes so it's first level (no level loading).

avatar image Niklas · Mar 13, 2011 at 12:57 PM 0
Share

Then he could do like !IsLoadingStuff. The same point applies

avatar image
0

Answer by Statement · Mar 11, 2011 at 07:47 PM

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();
}
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
  • 1
  • 2
  • ›

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Change LoadType of an AudioClip at runtime to StreamFromDisc 0 Answers

Problem with GetStreamProgressForLevel 0 Answers

Difference between LoadLevelAdditive and LoadLevelAdditiveAsync 1 Answer

How to speed up loading and optimize my game? 1 Answer

How to show an image while waiting for the game to finish loading 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges