• 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
0
Question by valentin-simian · Aug 18, 2015 at 07:04 AM · prefabresources.load

Will using Resources.LoadAsync() to load Prefabs reduce loading times in comparison to just referencing Prefabs in the Inspector?

Unity unadvises using Resources.Load() to load Prefabs as opposed to just referencing them:

In Unity you usually don't use path names to access assets, instead you expose a reference to an asset by declaring a member-variable, and then assign it in the inspector. When using this technique Unity can automatically calculate which assets are used when building a player. This radically minimizes the size of your players to the assets that you actually use in the built game. When you place assets in "Resources" folders this can not be done, thus all assets in the "Resources" folders will be included in a build.

http://docs.unity3d.com/ScriptReference/Resources.html

I need to load several things, but I don't require downloading things from my server like AssetBundles offers. I do, however, have several prefabs that not all users will use. If I use the LoadASync() method instead of just using a reference, will it take less time for my level to load?

Alternative solutions to the problem also welcome :^)

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

2 Replies

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

Answer by valentin-simian · Aug 19, 2015 at 06:11 AM

I found the fastest way to load multiple prefabs, of which only several may be used, is to incrementally load them by AssetBundles.

Even though the Unity Manual documentation implies their use by downloading AssetBundles from a server, it is possible to load them from drive using the file protocol via the WWW class.

Code for iOS, mostly cannibalized from @Dreamora:

 using UnityEngine;
 using System.Collections;

 public class AssetLoader : MonoBehaviour {

 void Awake ()
 {
     StartCoroutine(LoadBundle());
 }
 
 IEnumerator LoadBundle () {
     WWW test = new WWW("file://"+Application.dataPath + "/Raw" + "/YourAssetBundleName.unity3d");
     yield return test;

     Debug.Log(test + " WWW Test");
     
     // Load and retrieve the AssetBundle
     AssetBundle bundle = test.assetBundle;

     Debug.Log(bundle + " BUNDLE");
     
     // Load the object asynchronously
     AssetBundleRequest request = bundle.LoadAssetAsync ("your_game_object", typeof(GameObject));
     
     // Wait for completion
     yield return request;
     
     // Get the reference to the loaded object
     GameObject obj = request.asset as GameObject;
     
     // Unload the AssetBundles compressed contents to conserve memory
     bundle.Unload(false);
     
     test.Dispose ();
 }

}

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
0

Answer by YoungDeveloper · Aug 18, 2015 at 07:08 AM

Resources load is a much heavier operation, as data is read from drive. Accessing something by serialized variable reference is much faster.

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 valentin-simian · Aug 18, 2015 at 07:16 PM 0
Share

Implying that the referenced prefabs are loaded directly into RA$$anonymous$$? Arguably faster, as having less RA$$anonymous$$ will make further operations take more time to perform.

I'm reading elsewhere that I can load AssetBundles from drive via the file protocol using the WWW class. This way I can load and unload assets on request ins$$anonymous$$d of on load.

Will keep posted on final code.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Resources.Load() or Prefab manager? 1 Answer

How to get unique reference to instantiated prefab 1 Answer

Best practice instantiating objects from code 1 Answer

Resources not loading in APK 0 Answers

instantiated child prefab invisible 3 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