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 /
This question was closed Dec 08, 2018 at 07:57 PM by ZachVille for the following reason:

The question is answered, right answer was accepted

avatar image
1
Question by ZachVille · Nov 09, 2018 at 06:02 PM · c#applicationusing

Application.persistentDataPath not working

I am trying to create a save file but when I try to reference Application.persistentDataPath it says UnityEngine.Application does not contain a definition for persistentDataPath. I have UnityEngine included. Here is my code: using System.Collections; using System.Collections.Generic; using UnityEngine; using System; using System.Runtime.Serialization.Formatters.Binary; using System.IO; public class GameController : MonoBehaviour { public static GameController controller; public float maxHealth; public bool opened = false; void Awake () { if(controller == null){ DontDestroyOnLoad(gameObject); controller = this; Load(); } else if(controller != this){ Destroy(gameObject); } if(opened == false){ opened = true; maxHealth = 3; } } void Update () { if(Input.GetAxis("Exit") > 0){ Save(); Application.Quit(); } } public void Save(){ if(File.Exists(Application.persistantDataPath + "/playerInfo.dat")){ BinaryFormatter bfread = new BinaryFormatter(); BinaryFormatter bfwrite = new BinaryFormatter(); FileStream fileread = File.Open("file:" + Application.persistentDataPath + "/playerInfo.dat", FileMode.Open); PlayerData dataread = (PlayerData)bfread.Deserialize(fileread); dataread.maxHealth = maxHealth; dataread.opened = opened; PlayerData datawrite = new PlayerData(); datawrite.maxHealth = maxHealth; datawrite.opened = opened; bfwrite.Serialize(fileread, datawrite); fileread.Close(); } else{ BinaryFormatter bf = new BinaryFormatter(); FileStream file = File.Create(Application.persistentDataPath + "/playerInfo.dat"); PlayerData data = new PlayerData(); data.maxHealth = maxHealth; data.opened = opened; bf.Serialize(file, data); file.Close(); } } public void Load(){ if(File.Exists(Application.persistantDataPath + "/playerInfo.dat")){ BinaryFormatter bf = new BinaryFormatter(); FileStream file = File.Open(Application.persistentDataPath + "/playerInfo.dat", FileMode.Open); PlayerData data = (PlayerData)bf.Deserialize(file); file.Close(); maxHealth = data.maxHealth; opened = data.opened; } } [Serializable] class PlayerData { public float maxHealth; public bool opened; } } Please tell me what I am doing wrong and how to fix it.

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

  • Sort: 
avatar image
2
Best Answer

Answer by AaronXRDev · Nov 09, 2018 at 07:01 PM

In your code there are a couple spelling errors:

 Application.persistantDataPath //Note the "a" in "persistant"

vs.

 Application.persistentDataPath //Should be an "e"

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

Follow this Question

Answers Answers and Comments

95 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 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

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

C# Unity 3D Using functions from other files. 1 Answer

System.IO.File does not contain a definition for 'WriteAllLines' 1 Answer

How to send Printer the screenshot from unity to print. (without closing or opening another application) 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