• 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
Question by charnew · Feb 06, 2012 at 12:03 PM · standalonepreloader

Preloader for standalone

is there a way to make a preloader for a standalone build for windows, all the solutions i see are for web players

Comment

People who like this

0 Show 0
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

2 Replies

· Add your reply
  • Sort: 
avatar image

Answer by flamy · Feb 06, 2012 at 04:10 PM

 public int numberOfObjectsToLoad=4000;
     public int objectLoaded=0;
     public Texture tex;
     public bool nextLoad=true;
     
     
     // Use this for initialization
     void Start () {
         
         InvokeRepeating("nextLoadReset",0,0.1f);
         StartCoroutine("Load");
     
     }
     
     void OnGUI()
     {
         float temp=objectLoaded;                       // using temp variable because of some issues with accessing a variable from thread
         print((temp/numberOfObjectsToLoad)); 
         
         GUI.DrawTexture(new Rect(50,400,(float)500*(temp/numberOfObjectsToLoad)/* 500 is the width and the next calc is the percentage*/,50),tex);
     }
     
     void nextLoadReset()
     {
         nextLoad=true;
     }
     
     public IEnumerator Load()
     {
         
         for(int i=0;i<numberOfObjectsToLoad;i++)
         {
             
             yield return nextLoad;  //instead do your loading here  and btw using nextload for wait because wait for seconds wont work in thread (corotine)
             objectLoaded++;
             nextLoad=false;
             
         }
     }


this is just a sample of how you can do loading ! instead of using thread you can use different game states and check too but i prefer doin like this because it is simple...

if you are loading a 3d world make the renderer of all assets to false at the beginning (until everything else is loaded) Hope the code is clear !!

Comment
Bunny83
BiG

People who like this

2 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 Bunny83 · Feb 06, 2012 at 05:32 PM 0
Share

I just want to post that you can't use a Thread to load assets since Unity isn't thread-safe, but now you posted a coroutine solution with is of course the only way to reduce loading spikes. I wouldn't call it a preloader. It's just a load distributer. Unity loads all assets within a scene at once. All you can do is to use prefabs you instantiate one by one, but anyway all the prefabs are loaded at start.

Btw. i don't get the "nextLoad" stuff... There's no difference in yielding true or false. Both will wait exactly one frame. Why do you think that WaitForSeconds doesn't work in coroutines?

Finally: coroutines != thread
Coroutines are a kind of cooperative multitasking and not preemptive like threads.

avatar image flamy · Feb 06, 2012 at 05:54 PM 0
Share

wait for seconds is my bad i did a typo whn i coded it seems and checked the documentation (dang forgot default will be in js :P) and ya i know the difference between Coroutines and Thread.

and from his reply it seems like he needs a "loading bar" or progress bar so i thought this would be fine!! and obviously you got to do this with prefabs. It doesn't matter if prefabs are loaded at the beginning, but anyway copies could be created using this function, still it isn't too bad if you have to instantiate 100's of copies for each prefab!!. And pretty sure the reason he wants to go for a progress bar is because he gets stuck at splash screen for sometime (when actually unity loads the level), this would certainly help clearing that issue to an extend!!

avatar image

Answer by Bunny83 · Feb 06, 2012 at 01:24 PM

That doesn't make much sense. In a standalone build all data is available immediately. Preloader just make sense if you have to load the data from a slow connection. Even in Flash a preloader doesn't make sense if you run the swf-file local

Comment
BiG

People who like this

1 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 flamy · Feb 06, 2012 at 01:35 PM 0
Share

may be if he has numerous assets (like really lot!) he can use a thread to load it and give the user update on the loading bar!!

avatar image charnew · Feb 06, 2012 at 02:56 PM 0
Share

yes i have a lots of gameobjects that's why i need a progress bar

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Help required for shutting down compiled App 0 Answers

Unity Standalone CommandLineArgs 0 Answers

Is it possible to start Unity from a Win32 or .Net standalone project ? 0 Answers

how to make my own preload?, hide the mark of Unity, I want my game preload 2 Answers

unity3d read data from PostgreSQL 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