• 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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



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

Non Diagonal Physics Layer Editor? 1 Answer

Smooth Player Ball Rolling 1 Answer

How to bounce an object in random places on 2D screen 0 Answers

Priority Collisions 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges