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
1
Question by MacGyver · May 09, 2011 at 07:38 AM · instantiateprefabloadcomplete

Know when prefab has finished loading after Resources.Load

Hello everyone! I'm having an issue I'd like to solve. I don't have Unity Pro, so I cannot use AssetBundle or anything like that. I need to load multiple (heavy) prefabs into my scene. The loading process works perfectly, this is the code I'm using:

Object prefabObj = Resources.Load(path);
cellPrefab = new GameObject();
cellPrefab = (GameObject)Instantiate(prefabObj);

The object appears on the scene and I can interact with it. Problem is: some prefabs are very heavy, so Unity hangs and is not responsive for a few seconds. That's not an issue by itself, but I'd like to give the user a feedback of what's happening, something like "Loading started" and "Loading completed" on the GUI (I already have a status label). How exactly can I achieve that? Do I need to add some kind of script to the prefab?

Thank you all.

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
6
Best Answer

Answer by Bunny83 · May 09, 2011 at 08:21 AM

The best way would be to use a coroutine for your loading/instantiate-process to be able to give feedback after each step. Oh, by the way: you don't have to create an empty gameobject. That would just produce another empty and useless GO. Instantiate creates the whole prefab.

GameObject cellObj = null; bool loading = false;

IEnumerator LoadObj(string path) { loading = true; yield return null; // render another frame to make sure the label is drawn.

 Object prefabObj = Resources.Load(path);
 cellObj = (GameObject)Instantiate(prefabObj);

 loading = false;

}

void Start() { StartCoroutine(LoadObj("...")); }

void OnGUI() { if (loading) { GUILayout.Label("loading..."); } }

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 MacGyver · May 09, 2011 at 08:45 AM 0
Share

This is exactly what I was looking for. I appreciate it, thank you very much! :)

avatar image maggot · Mar 18, 2012 at 04:15 PM 0
Share

This is a great answer, and I used it to correct an error I had.

avatar image
0

Answer by Dreamer · May 09, 2011 at 08:05 AM

That's what loading screen in game does.

Use if(Application.isLoadingLevel) to check if a level is in loading. After loading finish you just hide the loading screen.(A full screen size 2D texture will do)

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 MacGyver · May 09, 2011 at 08:14 AM 1
Share

The problem is that I'm not loading a new scene, I'm loading a prefab into the current scene.

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

No one has followed this question yet.

Related Questions

Load a grid of cubes in the scene view before running level? 2 Answers

Unespected rotation for Instantiate object 1 Answer

How to reduce time of instantiating a prefab that contains many objects/components in it. 1 Answer

Visualization of saved games inside a Load Menu - Problem with instantiated prefabs 0 Answers

Terrain: Use as scenario (individual) and prefab (unchanged, reusable) 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