![]() The “Player” in “PlayerPrefs” actually refers to the Unity Player, the name of the standalone Unity Engine application that gets built when you turn your game into an application of its own. If you thought that the name “PlayerPrefs” alludes to the preferences of the player, you’re certainly not alone, but you are also incorrect. Well, the first clue (and point of confusion) comes from the name. With all these flags and eyebrows popping up, it’s pretty natural to wonder what exactly PlayerPrefs is used for if not for saving player progress data. The registry is really not used for that sort of thing and mainly saves system and application configuration data. This should be another red flag when considering saving game data with PlayerPrefs. In this case, if we are on a Windows computer, we can see from the docs that PlayerPrefs entries are saved to the registry. The file could be structured like a database or could be a simple text file, it just depends on what the application developers felt like doing. That file might be on a different computer across the country in the case of an online application, or it might just be in a sub folder called data. This may be something you haven’t given much thought to if you’re relatively new to programming, but saved data is just data that exists somewhere in a file. Location of saved dataĪnother important tidbit we can extract from the docs is where the location of the data from PlayerPrefs is actually saved. If we need to construct some sort of complicated string parsing system to mimic the behavior of a simple list, we might be barking up the wrong tree. This should be a big red flag for us when trying to figure out if this class is suitable for saving game data. You can probably envision a scenario where you would want to use a data type other than these three. You probably know that there are more data types than just string, float, and integer. Of course, then you also need to find a way to save a list of player IDs, which brings us to the next issue with using PlayerPrefs: you can only save data as a string, float, or integer. For example, you could choose to append a save file ID to each entry in PlayerPrefs and only load and save based on that ID. This means that if you want to have more than one save file for your application, you need to get creative. ![]() Method of saving dataįirst of all, PlayerPrefs saves data on a per-application basis. Right away, some things should raise some eyebrows. A good first step in this process is to check the docs for PlayerPrefs. Let’s start by taking a closer look at PlayerPrefs to see if it’s something we want to use to save our game data. The longer answer is that saving and loading data in Unity is actually a very deep topic without a clear best solution. The short answer is that saving a game state like this is generally a bad idea. ![]() This certainly seems to be about as easy as it gets, so it’s time to save some data, right? You can set a default return value if you haven't saved a "Level" yet with the second parameterĬurrentLevel = PlayerPrefs.GetInt("Level", 0) When you’re ready to load, getting the saved value is just as easy: PlayerPrefs.SetInt("Level", currentLevel) currentLevel is an integer variable representing the level the player is on All you need to do to save the level is the following: Well, this looks pretty easy in PlayerPrefs. You’ve decided you want to save the level your player is on when they quit the game so that the correct level loads back up when they start again. Let’s say you’ve made a simple game with some number of levels. With PlayerPrefs, you can have an easy-to-use interface that allows you to start persisting some data! We’ll also discuss reasonable alternatives to using PlayerPrefs. In this article, we’ll go over what PlayerPrefs is, how, when, and when not to use it. The simplest solution is a Unity class called PlayerPrefs. From this search, you may be surprised that there are quite a few different answers, all varying in complexity. If you’re like most of us, your first instinct might be to do a quick search on how to save player data in Unity. Whether you’re relatively new to developing in Unity or you’ve got a few projects under your belt, you’ve most likely realized how useful it would be for players to save data. Why you should (or shouldn’t) save data with Unity’s PlayerPrefs If you are still having problems opening UNITYWEB files, there may be other issues that are preventing you from opening these files.Brian Drake Follow Brian is the owner of UpRoom Games, a small independent game studio focused on creating unique experiences and sharing game dev knowledge in Unity. Other Causes of UNITYWEB File Opening ProblemsĪlthough you might already have Unity Web Player or another UNITYWEB-associated software installed on your computer, you can still encounter problems opening Unity Web Player files.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |