Forum rules - please read before posting.

Player moving to unexpected places, weird menu activation, after Load

edited January 2021 in Technical Q&A

(Happy New Year Adventure Creator Forum!)

I am getting two unwanted behaviours from my game after loading a scene from a saved game.

  1. In maybe half of the scenes in my game, if you load into them, the player moves to (what seems to be) a random place in the world, usually completely "out of bounds" far off-screen and off any navmesh present in the scene. It's always the same place per-scene, but the position is different in scene in which it occurs.

These scenes have OnLoad cutscenes set, most of which begin with the player spawning just off-screen and walking in through a doorway or similar. Whatever is sending them off on their rando-trek over-rules this movement, as if it cancels that move to point action the moment it starts. This behaviour occurs in scenes where no movement is specified in the OnLoad cutscene, and removing those actions doesn't effect it. Similarly, adding a object teleport action in to put the player somewhere doesn't circumvent it, in fact they still seem to walk from the default player start to the weird point, without being teleported at all. Also, this happens in scenes that have a default player start with specified previous scene activation and those that don't. There's no actionlist running at all when the player is walking.

  1. I've just added a little spinning UI animation that appears when the game saves. It's all fakery, simply turning on the menu, which is not enabled at start, and then turning it off a couple off seconds later in whatever actionlist had the save in it. But, whenever a scene is entered via a load, this little animation is always on, and doesn't turn off until another actionlist does so.

Any idea what might be causing these problems, even better, potential fixes?

Thanks for your help everyone!

-Martyn-

Comments

  • Please try to separate your issues by thread in future - it helps others with similar issues when searching.

    For the Player issue, I'm not sure from your description what the deciding factor is in causing this to occur vs not. Is it the presence of an OnLoad cutscene, i.e. if you unset it, the issue no longer occurs?

    What's your AC version, and how are you loading save files? Is there a difference in behaviour when being in the same scene before the load?

    Best to use a Debug Log to find the cause. Inside Char.cs, search for the MoveAlongPoints function, and insert the folling at the top of it:

    if (pointData.Length > 0 && IsPlayer) Debug.LogWarning ("Moving " + name + " to " + pointData[pointData.Length-1], this);
    

    That will cause a Warning to be placed in the Console every time the Player pathfinds somewhere. Just before loading, clear the Console, then get the issue to occur. Select the full messag that then appears in the Console, and copy/paste it here.

    For the menu issue, it depends on your Menu's "Appear type". If it's set to "Manual", it won't disappear until you tell it to.

    If you're loading save games via a Menu, you can specify an "ActionList after loading" asset file, that you can potentially give a "Menu: Change state" Action to turn the Menu off.

  • (I'll start a new thread about the menu issue, I thought they might be related, my bad!)

    So... That Debug Log prints a message to the console whenever the player moves via mouse click or a Character: Move to Point action is triggered. When this bug occurs on load? Nothing. Does that help us at all?

  • It's likely because the Player is resuming what they consider to be their motion at the time of saving.

    Remove the above line, and instead look for the private SetPath function. There are five SetPath functions in Char.cs, but only one is private. Paste the following at the top:

    if (pathOb.nodes.Count > 0 && IsPlayer) Debug.LogWarning ("Moving " + name + " to " + pathOb.nodes[pathOb.nodes.Count-1], this);
    

    How about then?

    Also, look up the save data for the save file using AC's Save File Manager (top of the Settings Manager). Look for the Player data, and share a screenshot of its contents.

  • Thanks for the follow up, let's see what we've got:

    On loading one of the offending scenes, the Debug.LogWarning prints 4 times, all with the same time stamp, moving the player to the same co-ordinates. Here they are, as they appear from top to bottom in the console:

    (1)

    Moving Avatar_F to (0.7, -9.4, 0.0)
    UnityEngine.Debug:LogWarning(Object, Object)
    AC.Char:SetPath(Paths, PathSpeed, Int32, Int32) (at Assets/AdventureCreator/Scripts/Character/Char.cs:2274)
    AC.Char:SetPath(Paths, Int32, Int32, Boolean) (at Assets/AdventureCreator/Scripts/Character/Char.cs:2398)
    AC.Player:LoadData(PlayerData) (at Assets/AdventureCreator/Scripts/Character/Player.cs:837)
    AC.PlayerPrefab:SpawnInScene(Boolean) (at Assets/AdventureCreator/Scripts/Character/PlayerPrefab.cs:130)
    AC.PlayerData:UpdatePresenceInScene() (at Assets/AdventureCreator/Scripts/Save system/PlayerData.cs:387)
    AC.SaveSystem:SpawnAllPlayers() (at Assets/AdventureCreator/Scripts/Save system/SaveSystem.cs:1755)
    AC.KickStarter:PreparePlayer() (at Assets/AdventureCreator/Scripts/Game engine/KickStarter.cs:1138)
    AC.KickStarter:Initialise() (at Assets/AdventureCreator/Scripts/Game engine/KickStarter.cs:1119)
    AC.MultiSceneChecker:Awake() (at Assets/AdventureCreator/Scripts/Game engine/MultiSceneChecker.cs:43)

    (2)

    Moving Avatar_F to (0.7, -9.4, 0.0)
    UnityEngine.Debug:LogWarning(Object, Object)
    AC.Char:SetPath(Paths, PathSpeed, Int32, Int32) (at Assets/AdventureCreator/Scripts/Character/Char.cs:2274)
    AC.Char:SetPath(Paths, Int32, Int32, Boolean) (at Assets/AdventureCreator/Scripts/Character/Char.cs:2398)
    AC.Player:LoadData(PlayerData) (at Assets/AdventureCreator/Scripts/Character/Player.cs:837)
    AC.PlayerPrefab:SpawnInScene(Boolean) (at Assets/AdventureCreator/Scripts/Character/PlayerPrefab.cs:130)
    AC.KickStarter:PreparePlayer() (at Assets/AdventureCreator/Scripts/Game engine/KickStarter.cs:1154)
    AC.KickStarter:Initialise() (at Assets/AdventureCreator/Scripts/Game engine/KickStarter.cs:1119)
    AC.MultiSceneChecker:Awake() (at Assets/AdventureCreator/Scripts/Game engine/MultiSceneChecker.cs:43)

    (3)

    Moving Avatar_F to (0.7, -9.4, 0.0)
    UnityEngine.Debug:LogWarning(Object, Object)
    AC.Char:SetPath(Paths, PathSpeed, Int32, Int32) (at Assets/AdventureCreator/Scripts/Character/Char.cs:2274)
    AC.Char:SetPath(Paths, Int32, Int32, Boolean) (at Assets/AdventureCreator/Scripts/Character/Char.cs:2398)
    AC.Player:LoadData(PlayerData) (at Assets/AdventureCreator/Scripts/Character/Player.cs:837)
    AC.PlayerPrefab:SpawnInScene(Boolean) (at Assets/AdventureCreator/Scripts/Character/PlayerPrefab.cs:130)
    AC.PlayerData:UpdatePresenceInScene() (at Assets/AdventureCreator/Scripts/Save system/PlayerData.cs:387)
    AC.SaveSystem:SpawnAllPlayers() (at Assets/AdventureCreator/Scripts/Save system/SaveSystem.cs:1755)
    AC.SaveSystem:ReturnMainData() (at Assets/AdventureCreator/Scripts/Save system/SaveSystem.cs:1326)
    AC.SaveSystem:InitAfterLoad() (at Assets/AdventureCreator/Scripts/Save system/SaveSystem.cs:625)
    AC.MultiSceneChecker:Start() (at Assets/AdventureCreator/Scripts/Game engine/MultiSceneChecker.cs:62)

    (4)

    Moving Avatar_F to (0.7, -9.4, 0.0)
    UnityEngine.Debug:LogWarning(Object, Object)
    AC.Char:SetPath(Paths, PathSpeed, Int32, Int32) (at Assets/AdventureCreator/Scripts/Character/Char.cs:2274)
    AC.Char:SetPath(Paths, Int32, Int32, Boolean) (at Assets/AdventureCreator/Scripts/Character/Char.cs:2398)
    AC.Player:LoadData(PlayerData) (at Assets/AdventureCreator/Scripts/Character/Player.cs:837)
    AC.SaveSystem:ReturnPlayerData(PlayerData, Player) (at Assets/AdventureCreator/Scripts/Save system/SaveSystem.cs:1504)
    AC.SaveSystem:ReturnMainData() (at Assets/AdventureCreator/Scripts/Save system/SaveSystem.cs:1327)
    AC.SaveSystem:InitAfterLoad() (at Assets/AdventureCreator/Scripts/Save system/SaveSystem.cs:625)
    AC.MultiSceneChecker:Start() (at Assets/AdventureCreator/Scripts/Game engine/MultiSceneChecker.cs:62)

    Perhaps relevant:

    Since my first post the way I load the scene has changed (initially I was using the example Unity UI Load menu with a single SaveList slot, now, when the player clicks continue on the title screen, I run a Save action that loads the autosave), and the coordinates the player moves to have changed too.

    And the save data:

  • Yes, it's coming from the fact that the Player is moving at the time of the save.

    Should this be the case? What is the Player doing at the time you make such a save, and do you rely on a Menu or Action for game-saving?

    One way you can ensure the Player never moves after loading is to hook into the OnFinishLoading event, and manually stop them via script:

    using UnityEngine;
    using AC;
    
    public class HaltPlayerAfterLoading : MonoBehaviour
    {
    
        void OnEnable () { EventManager.OnFinishLoading += OnFinishLoading; }
        void OnDisable () { EventManager.OnFinishLoading -= OnFinishLoading; }
    
        void OnFinishLoading ()
        {
            KickStarter.player.Halt ();
        }
    
    }
    
  • Saves mostly come from actionlists, or save & quit from the menu. I save in the auto save slot whenever the player gets an item, discovers a new location or finishes a conversation. This bug happens in both cases, and where the save is from an action list, the player is never moving (although there's often a move in that actionlist).

    Where would I put that script, and would it trigger before any movement in the OnLoad cutscene? I can remove moves from them if they represent a problem, but it's good to know before I go tinkering with 40 odd cutscenes :-)

  • The script just has to be present in the scene - it can be attached to your PeristentEngine prefab to have it be present everywhere automatically.

    It will, however, be called after the scene's OnLoad cutscene. It should only cause issue, though, if you move the Player in the first frame of such a cutscene.

    Give it a test first, but if this is the case - an Engine: Wait Action of -1 seconds at the start of your list will cause the ActionList to wait exactly one frame - i.e. after the script has kicked in.

  • @ChrisIceBox

    about
    KickStarter.player.Halt ();

    How can I iterate through all players here? The "inactive" players seem not to halt() with this code, only the active player.

  • edited March 2022

    Ok. found a solution:

         List<AC.PlayerPrefab> players = AC.KickStarter.settingsManager.players;
    
                foreach (AC.PlayerPrefab playerPrefabIterator in players)
                {
                    AC.Player playerIterator = playerPrefabIterator.GetSceneInstance();
    
                    if (playerIterator)
                    {
                        playerIterator.Halt();
                    }
                }
    
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.