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 Lyquifire · Mar 20, 2018 at 03:11 AM · fileresourcesfile-iofilestream

Text file in resource folder only gets updated when i quit.

I have a text file in the resource folder that holds some values that variables in my game use (ex: health, mana). I want the user to be able to write to that file from one scene, and load them in another. Its kind of working. Except when I press save the file gets changed but i need to quit unity or stop the play mode in order for these changes to commit. So if i change mana for example from 100 to 200, id have to exit and when i re-enter play mode its 200. I need that change to happen so that the next scene would read these variables. Also if im in play mode, and i change a value, when i open the text file in the editor it asks me to reload, and when i do the changes actually commit and im still in play mode, but i need that to happen in game alone. Would appreciate some help.

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

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by AlucardJay · Mar 21, 2018 at 04:50 AM

if im in play mode, and i change a value, when i open the text file in the editor it asks me to reload, and when i do the changes actually commit and im still in play mode

So I assume you are closing the file writer ok if the text file is being updated. You can refresh the project window view with :

 UnityEditor.AssetDatabase.Refresh();

https://docs.unity3d.com/ScriptReference/AssetDatabase.Refresh.html

You can also just refresh the text file with https://docs.unity3d.com/ScriptReference/AssetDatabase.ImportAsset.html

This is just for the editor (as you want to see the text file change in the editor), you may have to encapsulate the command in a platform dependant directive to avoid build complications, eg:

 #if UNITY_EDITOR
 UnityEditor.AssetDatabase.Refresh();
 #endif

https://docs.unity3d.com/Manual/PlatformDependentCompilation.html

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 Lyquifire · Mar 22, 2018 at 01:47 AM 0
Share

Yes that works but only in the editor, i want it to work in the build. AssetDatabase.Refresh(); only works in the editor. Im looking for a build solution.

avatar image Bunny83 Lyquifire · Mar 22, 2018 at 01:56 AM 1
Share

You want it to work in the build? Well that's not possible. Assets are generally readonly in a build. There actually isn't a resources "folder" when you create a build. How do you currently "save" / change the file? At runtime you want to either store a file in the persistent data path or use other ways to store your data. One way is using PlayerPrefs. PlayerPref(erence)s are specifically meant to store preferences of your game.

avatar image Lyquifire Bunny83 · Mar 22, 2018 at 02:11 PM 0
Share

PlayerPrefs where exactly what i needed, thanks! it worked

avatar image AlucardJay Lyquifire · Mar 22, 2018 at 02:14 AM 0
Share

Aah, I see now. I didn't factor in the Resources folder, was only focused on seeing the changes reflected in the editor. It is exactly as Bunny83 stated, here are the scripting reference links :

https://docs.unity3d.com/ScriptReference/Application-persistentDataPath.html

https://docs.unity3d.com/ScriptReference/PlayerPrefs.html

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

77 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

Related Questions

Loading an asset into the game post-build 0 Answers

Problem with path in FileStream 2 Answers

Unautherorized Access Excepetion on iOS8 1 Answer

Can not load csv file 0 Answers

File Browser that works on ipad + samsung + desktop 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