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
6
Question by duck · Jan 27, 2010 at 10:53 AM · savefile-io

Does Unity have an equivalent to browser cookies or Flash sharedObjects to save data?

Can Unity webplayers save data to the user's local PC, in the same way that Flash SWFs can save data using the actionscript "sharedObject" class, and that browser-based javascript can save data using cookies?

(the functions used to do this in Unity have been mentioned in a number of other answers on this site, but not specifically in the context of their equivalence to the Flash and Browser cookie functions used to save data).

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

Answer by duck · Jan 27, 2010 at 10:53 AM

Yes, web-based Unity content can save data to the local machine using the PlayerPrefs class. Each webplayer url can save up 1 megabyte of data, consisting of either ints, floats or strings. For example:

// to save an integer value PlayerPrefs.SetInt("Player Score", 10);

// to retrieve the integer value print (PlayerPrefs.GetInt("Player Score"));

And the commands are very similar for floats and strings:

PlayerPrefs.SetFloat("Player Lap Time", 29.3); print (PlayerPrefs.GetFloat("Player Lap Time"));

PlayerPrefs.SetString("Player Name", "Duck");
print ("Welcome back, " + PlayerPrefs.GetString("Player Name") + "!");

You can also query the player prefs data to see whether a certain key has been set, using PlayerPrefs.HasKey, and delete keys using either PlayerPrefs.DeleteKey or PlayerPrefs.DeleteAll.

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 Bill 2 · Dec 01, 2010 at 12:28 PM 0
Share

Looks handy. What about in the standalone versions?

avatar image duck ♦♦ · Dec 01, 2010 at 01:08 PM 2
Share

Works just the same in standalone builds!

avatar image Bill 2 · Dec 01, 2010 at 01:23 PM 1
Share

was just about to reply to my own comment and say the same thing. works great. Thanks

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

No one has followed this question yet.

Related Questions

WebPlayer call a server php script issue 1 Answer

Incremental Filename if it exists 3 Answers

How do I create multiple save files and make it work? 2 Answers

Generic Save and Load using BinaryFormatter not working 1 Answer

How to save and load node-based tree network data to a file? 1 Answer


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