• 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 jimbobuk · Dec 29, 2009 at 02:21 AM · iphone

How to speed up and smooth over any load times on iPhone (preloading, animated loading screens etc)

I am already aware of a big discrepancy with the load times of my app on my 1st generation iPhone versus my current 3GS. I'd like to do all i can to make my load times seem as snappy as possible.

I already know of the following suggestions

  • replace the splash screen (pro only)
  • load a small scene first to be quick and then start real loading

I've heard other suggestions that seem to hint at the potential of preloading gameplay assets by instantiating gameplay prefabs during the menu scene to have them available when you are actually in gameplay scenes. However its not clear to me how these instantiations trigger loading and dont get garbage collected moving between scenes. Wont adding instantiations of prefabs into the menu cause the menu scene to load slower, or is it by pure script instantiation that the actual scene wont load the prefab, rather it will on demand load it when the script instantiates it?

Are there any other better alternatives to this kind of preloading question, can AssetBundles be used locally as a decent way of loading things in an ordered fashion ahead of time.

Are preloading activities efficient if a user moves through your frontend so quickly that they're starting loading the game scene before any useful preloading has had chance to complete. Ie. will a half loaded asset have to be restarted loading again if the current scene is terminated and we head into the game scene proper?

When actually loading, is there a way to entertain the user whilst the loading is occurring, loading bar, music, animations etc. or are actual scene loads completely blocking and require a frozen (black?) screen?

Cheers

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

1 Reply

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

Answer by AMP · Jan 03, 2010 at 08:17 AM

That is quite a few questions. Consider posting multiple questions in the future if they get this long. Regardless, I think I can point you in the right direction.

First, it appears that System.Thread is supported. While your users are in the menu screen, you could have a thread routine run in the background and load all the GameObjects you will be using in the game. (Example below.)

To preserve all your game objects that you have loaded, you will need to call Object.DontDestroyOnLoad(/*your object reference*/) for each object. Alternatively, you could just add DontDestroyOnLoad(this) to the Awake() function of a MonoBehaviour script that is already attached to the loaded object. Note though that you will need to call Object.Destroy() if you decide to load a new scene and do not need those objects around anymore, otherwise they will persist until the application dies.

However, what about in the case if the user just blows through the menu screen and tries to jump into your game? I think there are two ways to deal with this.

The first way is to just block the user from starting the game by displaying a loading screen (e.g. using a GUITexture) with some sort of animation. Once the thread is finished, you can call Application.LoadLevel("Your Level"); to jump to the next scene. Of course, you still might have some down time while LoadLevel is invoked, so you could just make your loading screen object stick around with DontDestroyOnLoad() and then manually destroy it when the level is ready to go.

The second way is to note how far the thread has gotten, and then kill it. Put the note into some object that gets preserved into the next scene. When the new scene has loaded, continue loading where the previous thread left off. This is more complicated, however it might get your users playing faster if you prioritize the objects such that objects used sooner are loaded before objects that the player will not encounter for several seconds or more. You will need to use some sort of blocking mechanism if the user gets to a point where an object is needed, but it hasn't been loaded yet.

Threading example code:

// ... in some MonoBehaviour object public void Start() { m_thread = new Thread(threadExecute); m_thread.Start(); }

private System.Thread m_thread; private float m_value = 0.0f;

private void threadExecute() { // ... normally you would perform object instantiation here.
// Instead, lets do something intensive. This takes ~10 seconds // per pass on 2nd gen iPod Touch with OS 3.1.2, Unity iPhone 1.5.1. // int loopCount = 0; while( true ) { Debug.Log("threadExecute process start for iteration " + loopCount.ToString());

     for( int i = 0; i < 10000000; i++ )
         m_value = Mathf.Sqrt((float)(i * i * i));

     Debug.Log("threadExecute process end for iteration " + 
         loopCount.ToString());
     loopCount++;

     // ... ensure the thread will die if we stop playing in editor.  
     //     Otherwise, this thread will keep going until we start a 
     //     new debug session. :/
     if(! Application.isPlaying )  
         break;
 }
 Debug.Log("threadExecute is exiting");

}

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 jimbobuk · Jan 05, 2010 at 08:14 PM 0
Share

Thanks for the nice answer. You're right it is a bit of a wide topic, I kind of thought if i left it wide it could form a nice single place for all things to do with dealing with loading.

It'll take me some time to digest this, but it looks really encouraging.

One thing, are you saying by keeping objects alive between scenes you could have these objects giving you an animated loading screen WHILST Application.LoadLevel() (or whatever loading tasks do the actual heavy lifting of loading the scene) is completing?

Cheers

avatar image AMP · Jan 06, 2010 at 07:14 AM 0
Share

No, you loose all control while Application.LoadLevel() is executing. I did a quick test of this to confirm: Take a game object, and add a $$anonymous$$onoBehaviour script to it. $$anonymous$$ake sure DontDestroyOnLoad is called in Start(). In Update(), do a simple slow rotation of the game object: this.transform.Rotate(0, 0, 25 * Time.deltaTime); When LoadLevel is invoked, the object stops rotating until the new scene is ready to go. :/ During this time, I think the best thing to do is just show a static screen (with GUITexture) until you get control again.

avatar image AMP · Jan 07, 2010 at 06:22 AM 0
Share

I noticed that there is a function called Application.PreloadLevel()... this might avoid the control loss that occurs when Application.LoadLevel() is invoked. I don't see any documentation for it though.

avatar image muheydari · Oct 24, 2013 at 04:42 PM 0
Share

Application.PreloadLevel()??? there is no such function at all.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

1 Person is following this question.

avatar image

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

In priview good work, but on Iphone - incorect 2 Answers

Blocking particles then destroy then reduce health 0 Answers

iPhoneInput.acceleration, rotation within limits? 1 Answer

Is it possible to open the maps-application while running an unity-iphone app? 1 Answer


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