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 TauseefCVS · Sep 26, 2016 at 04:59 PM · c#playerprefsloadsavingonapplicationquit

onapplicationquit() function is not working with unity 4.6.3 (android)

Hi Guys

i am using unity 4.6.3 , on that version onapplicationquit() function is not working , i want to save playerprefs in that function but it is not save the values and game state and also use dontdestroyonload() function


using UnityEngine;

using System.Collections;

using System;

public class scriptss : MonoBehaviour {

 private void OnApplicationQuit ()
 {
     PlayerPrefs.SetInt ("chart", 0);
     PlayerPrefs.Save ();
 }

}

Comment
Add comment · Show 1
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 Zendist · Sep 26, 2016 at 08:11 PM 0
Share

$$anonymous$$ake void OnApplicationQuit() non-private.

3 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by Hanoble · Sep 27, 2016 at 09:08 AM

OnApplicationQuit() is NOT guaranteed to be called on Android. You can read more about that here, but Android activities that have been paused are NOT guaranteed to always give a Quit callback. Due to this design, many developers instead save crucial data at other points (scene loads, game over screens, checkpoint, etc). If you need this precise data on any application suspension (with a quit possibly ahead), a popular alternative is OnApplicationPause().

Instead of what you have, try this:

 private void OnApplicationPause()
  {
      PlayerPrefs.SetInt ("chart", 0);
      PlayerPrefs.Save ();
  }

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
avatar image
-2

Answer by Zendist · Sep 26, 2016 at 08:25 PM

OnApplicationQuit must not be private, in order for Unity to call the function when it closes the application. Simply remove the private keyword in front of void OnApplicationQuit().

Comment
Add comment · Show 1 · 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 Hanoble · Sep 26, 2016 at 08:57 PM 0
Share

I do not believe this answer is correct. Private is implicit in C#, meaning that if you simply put no private or public access modifier, it is treated as private. Removing the "private" from the method does absolutely nothing different than having the private there. The reason why a programmer would explicitly declare private is for better cross-language compatibility, and for other programmers to have no doubt about the structure of the class.

Just to clarify, these are the same:

 void OnApplicationQuit()
 {
      Debug.Log("Application quit");
 }

 private void OnApplicationQuit()
 {
      Debug.Log("Application quit");
 }

I also tested this in the editor, just to be sure there was nothing quirky here, and the private modifier changes nothing.

avatar image
0

Answer by TauseefCVS · Sep 27, 2016 at 06:24 AM

#imageHanoble there no difference in private and without private is work as same

OnApplicationQuit() working on Unity editor but not working on android build thats my question

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

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Saving with PlayerPrefs? How it works? 1 Answer

Saving and loading game with PlayerPrefs 1 Answer

Invalid floats in PlayerPrefs 3 Answers

C# Issues with either PlayerPrefs.SetVariable or UnityEvent.Invoke 1 Answer

How to save players rotation in Unity? PlayerPrefs 3 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