There are 40 StageCombatants with Status Value in the Player Faction.
Each Combatant is added to each GameObject in scene A (StageSelectScene) with the AddCombatant Component from the Inspector.
Since the Cobatant is to be saved, it is joined to the PlayerGroup from the script after the AddCombatant.
When transitioning to scene B, a list of StageCombatant is saved in SelectedData.
After transitioning to scene B, one StageCombatant corresponding to the scene name is restored from SelectedData. For example, "Combatant B".
Change the status of "Combatant B" restored in scene B.
Since the game may end at scene B, AutoSave after changing the status to resume from scene B in that case.
After transitioning to scene A, restore "Combatant B" in scene B to "Combatant B" in scene A.
The remaining 39 Combatants are restored from the StageCombatantList at the time of transition to scene B with matching names in the respective initialization scripts.
The restoration is done as follows in the script
private void SetCombatant(Combatant selectedStageCombatant)
stageCombatant = selectedStageCombatant;
selectedStageCombatant.GameObject = gameObject;
AutoSave after restoration is complete.
Do the same for the other scenes.
Go to scene C, change the status to "Combatant C", then return to scene A and restore.
These will work as intended as long as you do not exit the game.
However, when AutoLoad is performed and scene A is loaded, for some reason, all Combatants are returned to their initial state.
In the Save Game Settings, the Combatant is eligible to be saved.
Why is it that AutoSave should have been done, but AutoLoad initializes them?
I turned on RemenberCombatant in AddComponent to try it out and nothing changed.
When I look at the contents of the AutoSave File in a text editor, I see that the Combatant with the StatusValue of the value changed in scene B is successfully saved.
However, the Combatant instance with the desired information is not loaded.
I tried AutoSave, stopped Play mode, set AddCombatant to Disable in scene A, and AutoLoaded from the title screen, but this time the CombatantComponent was not attached.
Why this behavior?
Also, since this approach is not in the tutorial, I created it on my own. If I want to take over the Combatant across scenes like this, is there an easier way?