• 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 hodge47 · Oct 11, 2017 at 10:11 AM · wwwloading file

Invalid URI: Invalid port number - Loading Local File

So, I am loading textures in from a folder in the root directory of my project. I can get the file paths just fine, but when I feed the paths from an array I get an error of 'UriFormatException: Invalid URI: Invalid port number'. This code was working up until I upgraded to 2017.1 today. I searched on the net but couldn't find a solution. Is there a new way to get local files? Here's my code.

 public IEnumerator<WWW> GetSkins()
     {
         string[] skinFilePaths = Directory.GetFiles(skinsPath + "/", "*.png");
         for (int i = 0; i < skinFilePaths.Length; i++)
         {
             Debug.Log(skinFilePaths[i]);
             string url = "file:///" + skinFilePaths[i];
             WWW diskSkinDir = new WWW(url);
             string skinFileName = Path.GetFileName(skinFilePaths[i]);
             skinFileNames.Add(skinFileName);
             // Wait for file to finish loading
             while (!diskSkinDir.isDone)
             {
                 yield return diskSkinDir;
             }
             if (diskSkinDir.isDone)
             {
                 allSkins.Add(diskSkinDir.texture);
             }
         }
         Debug.Log(allSkins.Count);
     }

It does the same thing doing it this way too. https://docs.unity3d.com/ScriptReference/WWW.LoadImageIntoTexture.html

Comment
Add comment · Show 1
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 hodge47 · Oct 11, 2017 at 04:44 PM 0
Share

Reverted back to 5.5.4 which is what I was using before. Code works like a charm.

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Bunny83 · Oct 11, 2017 at 05:12 PM

if it has worked before it was most likely a bug. The file URI scheme uses forward slashes since it's an URI and not a file path. You should replace the backslashes with forward slashes.

Try this:

 string url = "file:///" + skinFilePaths[i].Replace("\\", "/");


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 hodge47 · Oct 11, 2017 at 07:26 PM 0
Share

It produces the same error, unfortunately. I think it's definitely a bug in 2017.1 since I can't find any updated api references. It makes sense to replace the backslashes, though, so thank you for that.

avatar image $$anonymous$$ hodge47 · Jun 26, 2018 at 03:31 PM 0
Share

Does work in 2017.3.1p3, did not in 2018.2.0b9. Difference besides version was using UNET in 2018.2.0b9. $$anonymous$$aybe it has something to do with port already used or something, but I don't think it's a version problem.

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

74 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image 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

Are there anyway to load ttf file as font at runtime already? 0 Answers

embed google maps into unity 3d 4 Answers

Is WWW.movie supposed to be this slow? 2 Answers

json (LitJSON) from PHP array.. How? 0 Answers

WWW didnt work on device ON UNITY 3.3? 2 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