Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 mateo4632 · Dec 22, 2016 at 01:08 AM · androidandroid buildandroid sdkstreamingassetsassetpath

Android Streaming asset path won't open

Hello, I am working on a mobile platformer game, which going to have a lot of levels. So I decided to find a way where I could draw the level, and base on the color of the pixels a certain prefab would spawn in at that spot. So I used quill18's script, which suited my needs perfectly https://www.youtube.com/watch?v=5RzziXSwSsg So this works just fine in the Editor, but once I test it on my android phone, the map doesn't load. So I'm unsure as to why it can't find the image. I'm placing the images in a StreamingAssets folder as well.

 public void LoadMap()
     {
         EmptyMap();
         manager.currentLevel += 1;
         levelFileName = manager.levels[manager.currentLevel].levelString;
         // Read the image data from the file in StreamingAssets
         string filePath = Application.streamingAssetsPath + "\\" + levelFileName;
         byte[] bytes = System.IO.File.ReadAllBytes(filePath);
         Texture2D levelMap = new Texture2D(2, 2);
         levelMap.LoadImage(bytes);
 
         // Get the raw pixels from the level imagemap
         Color32[] allPixels = levelMap.GetPixels32();
         int width = levelMap.width;
         int height = levelMap.height;
 
         for (int x = 0; x < width; x++)
         {
             for (int y = 0; y < height; y++)
             {
 
                 SpawnTileAt(allPixels[(y * width) + x], x, y);
 
             }
         }
     }


Any help at all would be greatly appreciated!

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
0

Answer by lamphung719 · Dec 22, 2016 at 03:39 AM

Have you checked whether the file is exist in that folder?

Comment
Add comment · Show 3 · 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 mateo4632 · Dec 22, 2016 at 07:32 PM 0
Share

@lamphung719 Yes I have checked and the file I am trying to open does exsist. As I said it works just fine in the Editor, but it can't be found on the Android device. Perhaps I am wrong, but maybe when I build it as an apk, the file may get deleted. But I have also tested that by placing a UI image with the source as that map image. So it's still there, but the script can't find it for some reason

avatar image lamphung719 mateo4632 · Dec 23, 2016 at 02:51 AM 0
Share

i mean in the device, did you check the file on the device, not the editor

avatar image mateo4632 · Dec 23, 2016 at 03:44 AM 0
Share

@lamphung719 Yes, like I said I made a UI image with the source image as the pixel map, so I know the map image is still there because if it wasn't the Image with the map on it would be blank. But if you know of another way I could check please do share! I also think I need to use another way of opening the image on android, but don't know how to yet.

 string filePath = Application.strea$$anonymous$$gAssetsPath + "\\" + levelFileName;

pretty sure this is my problem, I think I need to find the image another way for android.

avatar image
0

Answer by edcx · Dec 23, 2016 at 07:27 AM

Streaming Assets documentation says

For Android:

  path = "jar:file://" + Application.dataPath + "!/assets/";

Can you check with this path?

Comment
Add comment · Show 4 · 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 mateo4632 · Dec 23, 2016 at 07:00 PM 0
Share

Still no luck. Do you know of another way I could try to do this, Ins$$anonymous$$d of using the strea$$anonymous$$g assets folder.

avatar image Bunny83 mateo4632 · Dec 23, 2016 at 09:05 PM 0
Share

You should read the documentation more carefully. It clearly says that strea$$anonymous$$g assets are placed inside the AP$$anonymous$$ which essentially is a ZIP archive. The "jar:file:" URL scheme only works when using the WWW class. You can't use simply .NET file IO.

To quote the documentation:

This means that if you do not use Unity’s WWW class to retrieve the file, you need to use additional software to see inside the .jar archive and obtain the file.

If you just want to include the image directly in your game, Just create a public variable of type Texture2D like he did in the first place. You can't edit the image once the AP$$anonymous$$ is deployed as it resides inside the AP$$anonymous$$. You could however load custom maps from other paths on the device.

avatar image mateo4632 Bunny83 · Dec 27, 2016 at 05:36 AM 0
Share

Oh silly me, I wasn't really thinking at the time, yes putting all the textures into an array makes more sense and is much easier! Thanks for help!!!

avatar image mochadwi20 · May 19, 2017 at 03:18 PM 0
Share

Ins$$anonymous$$d of getting the actual files from Android, it's check for our PC ins$$anonymous$$d (debuggin using Unity Remote on my Android). Application.dataPath is pointing to my projects.

Is there any workaround to this?

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

109 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 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

Always ask to updating android SDK 4 Answers

One Signal dependecies issue 0 Answers

Can't install openJDK 1 Answer

Multiple errors: Gradle/SDK/JDK related. Unity android build 5 Answers

Issue building my game for Android 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