For some reason when I build the game and play the times will not save. If I play the game in unity it does. The strange thing is that if I go back to the build version the times show up and it write new ones. I was wondering if there something else I have to do to make it be able to create a data file. I think it has something to do with the try catch function. Even if there is a file made it still goes to the catch instead of the try.
That’s an interesting error - it looks like it’s searching in the Bobblehead Wars directory. @shogan, any thoughts on this one?
That the name of the game. Right now all three games are in one game.
I’m sorry I’m only getting back to you now.
I think I know what your issue is though. The problem with the weird path referencing Bobblehead Wars, is that you have all games in one Unity project. Saved data will be persisted to a directory in your computer’s user profile based on the name of your Unity project.
Specifically the Company Name and Product Name you assign in the project is used for the path where data is saved.
Check your project settings and you’ll see that the project you’re using is named “Bobblehead Wars”, and I guess you’ve got the Super Soy Boy project files in the same project?
Super Soy Boy should ideally be in it’s own Unity project, so try that to resolve the weird path issue.
For the exception you’re seeing, the GameManager.cs class for the final project (i.e. what you have had the end of the Saving Data chapter) expects saved times to be in a specific format of playerName_levelname_times.dat
This is the code in GameManager.cs that sets up the file name for loading:
var levelName = Path.GetFileName(selectedLevel); var filePath = Application.persistentDataPath + "/" + playerName + "_" + levelName + "_times.dat";
You have a couple dependencies here. First the player name (which you seem to already have set as “Will”.
The second is a level name. You should load either the Level1 or Level2 game scenes in the project, then click the Level GameObject in the Hierarchy, and type a level name in the Inspector field for Level Name. Then click the Save button.
This will output the level as a JSON file to your game path.
Launch the game again, but make sure you launch using the Menu scene. You’ll see your saved level in the list of levels to play.
Launch the level from that UI and your save/load of level times will work
Hope that helps!
PS @bdmoakley thanks for pinging me here - it notified me, but the email got drowned out by a bunch of others initially and I missed it!
It wasn’t that the problem. I think it was the API compatibility Level it was set a .NET 2.0 subset. I changed it to .Net 2.0 and it works.
@ghostwolf Really glad you fixed it! Cheers! :]