# Soyboy save function

**URL:** <https://forums.kodeco.com/t/soyboy-save-function/100747>\
**Category:** Unity Games by Tutorials\
**Created:** [March 6, 2020, 3:40am UTC](https://forums.kodeco.com/t/soyboy-save-function/100747 "2020-03-06T03:40:05Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![ghostwolf](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/ghostwolf/32/81494_2.png) [@ghostwolf](https://forums.kodeco.com/u/ghostwolf)\
**Post date:** [March 6, 2020, 3:40am UTC](https://forums.kodeco.com/t/soyboy-save-function/100747/1 "2020-03-06T03:40:05Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![ghostwolf](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/ghostwolf/32/81494_2.png) [@ghostwolf](https://forums.kodeco.com/u/ghostwolf)\
**Post date:** [March 17, 2020, 1:18am UTC](https://forums.kodeco.com/t/soyboy-save-function/100747/2 "2020-03-17T01:18:07Z")

</div>

![image](https://files.chunter.kodeco.com/original/3X/5/7/579aaa7048ab0cbaa271aeda6076788a098d5630.jpeg)  
This is the error I get.

---

<div class="post-metadata">

**Author:** ![bdmoakley](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/bdmoakley/32/108772_2.png) [@bdmoakley](https://forums.kodeco.com/u/bdmoakley)\
**Post date:** [March 17, 2020, 1:33am UTC](https://forums.kodeco.com/t/soyboy-save-function/100747/3 "2020-03-17T01:33:01Z")

</div>

That’s an interesting error - it looks like it’s searching in the Bobblehead Wars directory. @shogan, any thoughts on this one?

---

<div class="post-metadata">

**Author:** ![ghostwolf](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/ghostwolf/32/81494_2.png) [@ghostwolf](https://forums.kodeco.com/u/ghostwolf)\
**Post date:** [March 17, 2020, 2:20am UTC](https://forums.kodeco.com/t/soyboy-save-function/100747/4 "2020-03-17T02:20:43Z")

</div>

That the name of the game. Right now all three games are in one game.

---

<div class="post-metadata">

**Author:** ![shogan](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/shogan/32/91487_2.png) [@shogan](https://forums.kodeco.com/u/shogan)\
**Post date:** [March 25, 2020, 5:23pm UTC](https://forums.kodeco.com/t/soyboy-save-function/100747/5 "2020-03-25T17:23:02Z")

</div>

Hi @ghostwolf,

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!

---

<div class="post-metadata">

**Author:** ![ghostwolf](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/ghostwolf/32/81494_2.png) [@ghostwolf](https://forums.kodeco.com/u/ghostwolf)\
**Post date:** [March 28, 2020, 2:30am UTC](https://forums.kodeco.com/t/soyboy-save-function/100747/6 "2020-03-28T02:30:41Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![shogunkaramazov](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/shogunkaramazov/32/108826_2.png) [@shogunkaramazov](https://forums.kodeco.com/u/shogunkaramazov)\
**Post date:** [April 6, 2020, 8:42am UTC](https://forums.kodeco.com/t/soyboy-save-function/100747/7 "2020-04-06T08:42:46Z")

</div>

@ghostwolf Really glad you fixed it! Cheers! :]

---

<div class="post-metadata">

**Author:** ![system](https://s3.amazonaws.com/cdn.raywenderlich.com/community/forum-assets/noun-game-ghost-878668.png) [@system](https://forums.kodeco.com/u/system)\
**Post date:** [August 19, 2020, 7:40pm UTC](https://forums.kodeco.com/t/soyboy-save-function/100747/8 "2020-08-19T19:40:08Z")

</div>

This topic was automatically closed after 166 days. New replies are no longer allowed.
