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)
{
ORK.Game.Combatants.Remove(stageCombatant);
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?
  • Well, because scene A's combatants are just initialized again when you load that scene, because the Add Combatant component adds it to the game object.

    There's no built-in functionality to take non-player combatants across scenes. One way to solve this is e.g. using a 2nd player group (via player group IDs) that hold all of those combatants and either use schematics or custom scripts to add them to game objects in your scenes or spawn them.
    Please consider rating/reviewing my products on the Asset Store (hopefully positively), as that helps tremendously with getting found.
    If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
  • to add them to game objects in your scenes or spawn them.
    Can you give me some more tips?
    I am trying to do this in schematics.
    Are you saying that I should use the AddCombatant node in schematics?
    When I look at the AddCombatant node settings it looks like it initializes first.
  • It's actually pretty simple - write a custom component that lets you define the group ID and member index you want to use (both int values) and use this code in the Start function:

    Group otherGroup = ORK.Game.PlayerHandler.GetGroup(groupID);
    Combatant combatant = otherGroup.MemberAt(memberIndex);
    combatant.GameObject = gameObject;


    Maybe add some null checks to make sure there is stuff returned, but that's basically all you need to do. Get the player group those combatants are part of and define the index of the member.
    Group ID 0 is the default player group that you start with, so add those non-player combatants to another group ID (e.g. 1). The member index is basically the order they joined in, so index 0 is the first, index 1 is the 2nd, etc.
    Please consider rating/reviewing my products on the Asset Store (hopefully positively), as that helps tremendously with getting found.
    If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
  • edited September 2023
    Thank you!I trying.
    Post edited by joeee19 on
  • Thank you!
    I tried many things with the script you gave me and finally got the following script to work perfectly!
    ORK and Makinom are great solutions.
    using GamingIsLove.Makinom;
    using GamingIsLove.ORKFramework;
    using UnityEngine;

    public class LevelSceneStageCombatantInitialize : MonoBehaviour
    {
    Combatant stageCombatant;
    [SerializeField] public CombatantAsset thisStageCombatantAsset;
    [SerializeField] public CombatantGroupAsset stageCombatantGroupAsset;

    void Start()
    {
    // StageCombatantのグループ(1)の存在チェック
    // このシーンからテストプレイ開始した場合はグループが存在しない
    if (!ORK.Game.PlayerHandler.GroupExists(1))
    {
    ORK.Game.PlayerHandler.AddGroup(1);
    stageCombatantGroupAsset.Settings.Join(ORK.Game.PlayerHandler.GetGroup(1), false, Vector3.zero);
    }
    Group stageCombatantGroup = ORK.Game.PlayerHandler.GetGroup(1);
    stageCombatant = stageCombatantGroup.GetMember(thisStageCombatantAsset.Settings);
    stageCombatant.GameObject = gameObject;
    Maki.Game.SelectedData.Change("StageCombatant", stageCombatant, ListChangeType.Set);
    }
    }
Sign In or Register to comment.