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
0
Question by pitzav@gmail.com · Apr 01, 2013 at 09:45 AM · instantiatewebplayerwwwloadassetatpath

I cannot load an asset in web player with instantiate

Hi i a very new to unity, I have a problem with instantiate in web build. I cannot load an object in web player. When i try to load it in editor it loads perfectly.

This is the code that i use

if (Application.isEditor) { assetPath = "file:///" + Application.streamingAssetsPath + "/" + thumb + goniakos + "" + width + length + ".unity3d"; var eee = Application.streamingAssetsPath + "/" + thumb + goniakos + "" + width + length + ".unity3d"; } else {

 message += " isNotEditor";
 assetPath = Application.dataPath + "/StreamingAssets" + "/" +   thumb  + goniakos + "_" + width + length +  ".unity3d";
 eee = Application.dataPath + "/StreamingAssets" + "/"  + thumb  + goniakos + "_" + width + length +  ".unity3d";
         }

 message += assetPath;
 var www = new WWW(assetPath);
         
 var instance : GameObject = Instantiate(www.assetBundle.mainAsset);

message += " isNotEditor";

thumb, width, and length are variables

When i print the variable assetPath its a valid http address but the object doesent load

Thank you

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

Answer by TonyLi · Apr 01, 2013 at 02:15 PM

In the web player, you need to give it time to download. Between "new WWW()" and "Instantiate()", call "yield return www" or check "isDone":

 var www = new WWW(assetPath);
 yield www;
 var instance : GameObject = Instantiate(www.assetBundle.mainAsset);
Comment
Add comment · Show 7 · 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 TonyLi · Apr 01, 2013 at 05:33 PM 0
Share

I tried that but the above code is inside a OnGUI function and the yield throws an error, that says OnGUI() cannot be a coroutine

Then ins$$anonymous$$d of "yield www", check www.isDone. When www.isDone is true, this means the download is done and you can instantiate objects.

avatar image pitzav@gmail.com · Apr 01, 2013 at 08:52 PM 0
Share

can i use www.isDone with javascript?

avatar image TonyLi · Apr 01, 2013 at 11:40 PM 0
Share

Yes. Just keep checking each OnGUI() until www.isDone returns true.

Refer to: http://docs.unity3d.com/Documentation/ScriptReference/WWW.html

avatar image pitzav@gmail.com · Apr 02, 2013 at 07:48 AM 0
Share

if((www.isDone == true)){

this doesent work what am i doing wrong?

avatar image TonyLi · Apr 02, 2013 at 01:01 PM 0
Share

What error does it report?

Consider moving your code out of OnGUI() and using yield. For example, the sample code is in Start(). (See the WWW.html link in my previous comment for the sample code.)

Show more comments

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

12 People are following this question.

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

Related Questions

Download assetBundle from server 2 Answers

Block-based terrain: WWW image problem and performance help? 0 Answers

WWW Error in Web Player 1 Answer

Assetbundle materials? 1 Answer

Image files from folder with System.IO into array converted to WWW.texture and applied to Instantiated prefab 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