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
1
Question by Kamil1064 · May 10, 2016 at 03:20 PM · physicsload asset

File exist, path is null but isn't C#

Hi, I'm trying to load file as text. This is working in editor but not in build:

 BinaryFormatter bf = new BinaryFormatter();
 FileStream file = File.Open("Assets/Door/Resources/Saves" + "/myGame_" + saveLevelInt + "_" + saveSlotInt + ".txt", FileMode.Open);
 playerData data = (playerData)bf.Deserialize(file);
 file.Close ();
 // do rest

Because it's not working in build I tried to use Resources.Load but it looks like I miss something, here is code:

 BinaryFormatter bf = new BinaryFormatter();
 TextAsset hila = (TextAsset)Resources.Load("Saves/myGame_" + saveLevelInt + "_" + saveSlotInt, typeof(TextAsset));
 if(hila == null)
 print("there is no file");// never prints if not modify path and file exist in folders

 FileStream file = File.Open(hila.ToString(), FileMode.Open); // in this line i get error**
 playerData data = (playerData)bf.Deserialize(file);
 file.Close ();
 //do rest

**that error:

ArgumentException: Path is empty.

Problem is I cannot make saves in runtime, they are always from files made before game is builded. It's specyfic case :D

Comment
Add comment · Show 5
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 saud_ahmed020 · May 11, 2016 at 07:20 AM 0
Share

@$$anonymous$$amil1064 You need this one :P

http://answers.unity3d.com/questions/279750/loading-data-from-a-txt-file-c.html

avatar image Nerevar · May 11, 2016 at 07:36 AM 0
Share

Hello,

Not sure that Hila.ToString() will actually work, maybe try hila.Text (doc)

ANd use if(String.IsNullOrEmpty(hila.Text)) print("...");

avatar image Kamil1064 Nerevar · May 11, 2016 at 08:20 AM 0
Share

Hi @Nerevar, now it prints always :( Trying now to understand links which @saud_ahmed020 gave. Edit: $$anonymous$$odified line to:

 TextAsset hila = (TextAsset)Resources.Load("Saves/myGame_" + saveLevelInt + "_" + saveSlotInt + ".txt", typeof(TextAsset));
 if(string.IsNullOrEmpty(hila.text))
 print("something wrong"); // now never prints if file exist in folder but get bug:
 //NullReferenceException: Object reference not set to an instance of an object// in line above
 // "if(string.IsNullOrEmpty(hila.text))"

I made hila as public TextAsset, then trying to File.Open... but then path is null as on first post :(

avatar image saud_ahmed020 · May 11, 2016 at 08:56 AM 0
Share

@$$anonymous$$amil1064 try this http://docs.unity3d.com/ScriptReference/Application-persistentDataPath.html

avatar image Kamil1064 saud_ahmed020 · May 11, 2016 at 09:56 AM 0
Share

@saud_ahmed020 I tried but it's missing when i move application between computers :(

0 Replies

· Add your reply
  • Sort: 

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

62 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

Related Questions

2D 360 degress platformer example needed 0 Answers

How does Totally Accurate Battle Simulator's physics and animations work? 0 Answers

Active rigidbodies and number of Contacts 1 Answer

Bullet getting repelled when coming closer to it's spawn point. 1 Answer

The faster my character goes the longer he jumps. 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