Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Sarthak123 · Oct 21, 2014 at 01:44 PM · classsave data.txt

Is There Any Way To Save A Variable Into a .txt file?

Ok so is there any way by which i can save a variable, such as score, points, etc. in a .txt file? which i can load later in the game...? i know we can use playerprefs.SetInt() and PlayerPrefs.GetInt() to save a variable very easily but i am curious if we could save it into a .txt or any other file format? using the unity I/O?

let the variable be...

 var MyScore : int = 10;

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
3
Best Answer

Answer by HarshadK · Oct 21, 2014 at 01:48 PM

Watch this video: PERSISTENCE - SAVING AND LOADING DATA

It nicely describes many aspects of how to read and write to files.

Also you can use any file extension as you like let it be .txt, or .dat, or .blablablabla.

Specifically for text file read this: How do I write a line of text to a file?

Now you can do research further on how to read similarly.

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 Sarthak123 · Oct 21, 2014 at 02:24 PM 0
Share

yes, @harshadk thanks again i found this somewhere...

 System.IO.File.WriteAllText("D:/Save/posX.txt", posx.ToString());

i used it and it worked...

similarly i tried replaciing Wri$$anonymous$$llText with ReadAllText and astonishingly i was able to read the data also...

I wanted to create my own save game system rather any built in or ready made system..

avatar image Cherno · Oct 21, 2014 at 03:05 PM 1
Share

You could also look into saving to a X$$anonymous$$L file if you want some more structure. Useful if your save game data is mroe than a simple variable.

avatar image Sarthak123 · Oct 22, 2014 at 09:50 AM 0
Share

right now i need only to save 4 simple variables, namely players coordiantes, health, resource and score...

i will also see to X$$anonymous$$L file saving system for unity

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

I have a class containing my settings/player stats. How would I serialize the whole class at once in order to save load? 2 Answers

How to make a editable text list using external text file 1 Answer

How to use corutines in a class 1 Answer

JS to C# class conversion issue. 1 Answer

Declare new class[].vector3[] length? 2 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