Hello
As the title says, when loading a game, certain things are retained in the player from before.
Scenario 1:
The player puts on a hat, the speech portrait picture is changed to one where he is wearing a hat. The player object also has a hat object become visible on its head. Now load a game from before he put on the hat. The player object hat is NOT visible (so this is working) but the portrait is still the one where he is wearing the hat.
Scenario 2: The player sits down on a chair. He uses mecanim for animation, so a bool parameter is set to make him sit. Now load a saved game. The character is still in the sitting animation.
This only happens when loading a game directly from another scene directly from the pause menu. This does not happen when the game is ended and sent back to the start screen and a game is loaded from there.
When the load option is selected from the pause screen this is what happens:
(I have tried 2 different things both with the same undesired result)
Way 1:
Save->Save or load
Method: Load Game
Save to load: Autosave
Selective loading?: false
Way 2:
Engine->End game
Command: Load Autosave
When ending and then loading this is what happens:
Select "Main Menu" from pause menu:
Engine->End game
Command: Restart Game
Choose scene by: Name
Scene to restart to: MainMenu
Reset Menus too?: true
Load game from main menu:
Save->Save or load
Method: Load Game
Save to load: Autosave
Selective loading?: false
Any ideas?
AC 1.64.5
Unity 2019.1.9f1
It looks like you're new here. If you want to get involved, click one of these buttons!
Comments
In order to save a change in portrait texture, both the original and new textures must be given unique filenames and placed in a Resources asset folder. See the Manual's "Saving asset references" chapter for more.
In order to save the state of the Player's Animator, attach a Remember Animator component to the same GameObject as the Animator.
Adding Remember Animator to the player fixed that one.
However, the portrait issue isn't a problem with it not saving. It is saving. The textures are in a Resources folder and it's saving them just fine. I can quit the game and come back and restore and he has the right portrait image. However, if the game is loaded while in another scene, it retains the portrait image from the scene it was loaded from rather than the one that was saved with the save file. If I then quit the game, and come back and restore from the main menu, he has the right portrait image, the one that was saved.
So when you load from the same scene, or the main menu scene, it's correctly loaded - but not when you load from a specific other scene?
Is the Player present in the Main Menu scene, and what about loading from other scenes? We will need to determine if this is a behaviour unique to this other scene.
Most scenes auto save when you enter them, in the Onload Cutscene (which is always called from the OnStart cutscene). So restoring a game from within a scene usually just backs you up to the moment you entered that scene.
However, there are two scenes back to back which do not autosave. In the first of these scenes, the Player puts on a hat and his portrait changes. Then if you restore during either of these 2 scenes, he still has the hat on in the restore. After these two scenes, it saves again. He's still wearing the hat, but restoring at that point just backs you up to when you entered the scene (and had the hat) so keeping the hat portrait is fine in that case.
So it's only an issue in these two scenes but that's only because these are the scenes between saves when he puts on the hat so it would only be noticeable in that case.
Yes, there is a player start in the main menu screen and he gets instantiated there, although not visible.
This is getting more and more baffling. Two new pieces of information.
I disabled the autosave on the scene after those 2 scenes. If I restore from that one, he reverts to his non-hat portrait.
I started the game and restored a game in which he was wearing the hat. Then I went back to the main menu and started a new game. In the new game, he had the hat portrait from the beginning.
Just did #2 again and kept an eye on the object. When the game ends and gets sent back to the main menu, it does appear to destroy his object and create another one from the prefab, but his portrait is still whatever it was from the last scene. So he has the hat portrait in the Main Menu scene, if you go back there from a scene where he had the hat.
So you're only dealing with a single autosave file?
I can't recreate any issue in initial testing. With an issue like this, minute details are key. I would need a list of clear steps on how to reliably recreate the issue, starting from a fresh set of Managers created using the New Game Wizard. Operations like creating a Subtitle menu that shows the dialogue portrait can be glossed over.
Also of note:
1) You should upgrade to the current release (in a duplicate/test project), to see if this has been addressed since.
2) The restoration of the portrait texture occurs in the Player script's LoadPlayerData method:
Replacing that line with the following may reveal some clue in the Console window upon loading:
By using those debug messages and keeping an eye on the player's portrait, I discovered that it is correctly restoring the portrait image on the player whenever a game is loaded. However, it is not using the portrait image that's on the player.
I created a new project and easily recreated the problem. Here's a gif of the outcome. This is using the newest AC version.
To make this project, just make 2 scenes.
In the first scene, make an onStart that calls an Onload that does nothing but has Autosave After? checked true on it
make a hotspot that makes the player say something, and another that switches to the second scene
In the second scene in onstart call onload. In onload, switch the player's portrait image. Do not autosave this scene. have a hotspot that makes the player say something.
after switching to the second scene and the player talks, when you restore back to the first scene, the player still has the second portrait image. You can see in the gif that it is restoring it in the player object, but it's not using that one.
This only happens if the player speaks in the second scene. If you restore without having the player speak, it uses the right portrait image.
The other issue, which may or may not be somehow related is that when the game ends, the player still has whatever portrait he last had. There is an easy workaround for this one by just setting the portrait back in the OnStart of the Main Menu scene, but seems like the player should revert to defaults when the game is ended.
Thank you - I shall follow these steps and see where it takes me.
AC can only restore data that has been previously saved. In the case of the game ending (and presumably using the Ending: End game to restart), changes made to the player prefab are one of the few areas that would have to be reset manually.
Recreated - this is not to do with loading, but to do with Unity UI. You should find that switching your subtitles menu's Source back to Adventure Creator displays the correct portrait.
I will introduce a fix in the next update.
Is there a quick hack for this besides switching to an Adventure Creator menu? My game releases in about 5 weeks and trying to get the remaining bugs out.
In Player.cs, look for the following line in it's LoadPlayerData method:
Paste the following underneath it: