• 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 kyopolo · Apr 11, 2012 at 10:26 AM · iosfileresourcesread

Can unity read file in iOS folder?

hi all, I am trying read file in iOS folder but it failed.

in xcode , i let my ipad to download file and save it

like this

//download in xcode

-(void)connectionDidFinishLoading:(NSURLConnection *)connection {

 NSArray *pathLis = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);   
 NSString *path = [pathLis objectAtIndex:0];
  
 path = [path stringByAppendingPathComponent: @"aaa.unity3D"];
 
 if([tempData writeToFile:path atomically:NO])
 {
     NSLog(@"YES"); 
 }
 else
 {
     NSLog(@"NO");
 }
 NSLog(@"save as %@", path);
 //[tempData release];
 //tempData = nil;

}

this works fine , download is ok , saving file is ok,too. but when i want to load the file in unity. it failed.

in unity i try this command

Resources.LoadAssetAtPath( Application.persistentDataPath+"/aaa.unity3D");

or WWW bundle = new WWW(file://+Application.persistentDataPath+"/aaa.unity3D"); etc..

i try any path i find in web

and i sure the path is right.

because this works great in uinty

FileStream fs = new FileStream(Application.persistentDataPath+"/aaa.unity3D", FileMode.Open, FileAccess.Read);

why?

the FileStream is byte[]

i don't know how to change to prefab or other type i wnat to use in unity.

C# "filestream" can read the file in iOS

but "Resources.LoadAssetAtPath" fail

and the path is 100% same

Anyone know about this?

or how can i change byte[] to unity object?

Sorry for my bad english~

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

Answer by Graham-Dunnett · Apr 11, 2012 at 10:35 AM

Resources.LoadAssetAtPath is documented as being useful in the Editor only, and the path name you give the API is a path name into the Assets folder in the Unity project.

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 kyopolo · Apr 12, 2012 at 02:13 AM 0
Share

So , i can't use Resourcesload to read file in iOS folder . but what about the WWW? it fails ,too. is that the same reason like resourcesload? WWW useful in Editor only?

Is there other way to read iOS folder by using unity? because i don't know how to change byte[] to unity prefab or unity gameobject.

Thanks to answer me~

avatar image rutter · Apr 12, 2012 at 02:26 AM 0
Share

What file are you trying to load? Is it an asset bundle that you've created with the Unity editor previously? If so, WWW.assetBundle should work if you have things set up right. Are you getting any particular error messages?

avatar image kyopolo · Apr 12, 2012 at 02:31 AM 0
Share

yes , the file is assetbundle , or even jpg.

I try WWW but it is not work , error log is null , i also check the progress, but it always "0". I don't know what is wrong. And i am sure the path is right. because filestream is work by use the same path.

by the way , if i use WWW to link the webpath , the log says "badpath" . So i download the file by using xcode , and save file in the ios snadbox folder. then i use WWW to the path like this "WWW(file://+Application.persistentDataPath+"/aaa.unity3D");"

avatar image
0

Answer by kyopolo · Apr 12, 2012 at 07:33 AM

oops , the web part is my fault , it is because the assetbundel's problem. but that question is still , when i download the file in ipad. i use WWW to read the localfile , the WWW.isdone == true; but when i want to Instantiate it , it shows the log "Failed to load asset bundlel" the file is the same in my website. Anyone know about this?

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

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Why a 109kb .png file teakes 8mb in unity? 1 Answer

A node in a childnode? 1 Answer

How do I read unicode text file on IOS from resources folder? 1 Answer

Access path of stored asset 0 Answers

Make an object move in the direction of touch 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