Forum rules - please read before posting.

Issues with save game loading global variables linked to Playmaker variables

AC v1.75.3, Unity 2019.4.26f1

Hey, I've been trying to work out what's happening here to no avail.

I have a fully functional combat/weapons system created using Playmaker and with ammo variables linked to Adventure Creator, I use these ammo variables to add/remove inventory items (weapon with loaded ammo, empty weapon, bullets item etc) through AC actionlists.

The system is functioning perfect, you can pick up ammo, it is added to AC inventory with an item count representing the amount of ammo. You can reload and the gun will no longer show empty, bullets will be deducted as they are loaded into the weapon etc. Everything is sync'd to AC using four global variables, Pistol1Ammo, Pistol1LoadedAmmo, Shotgun1Ammo, Shotgun1Loaded ammo.

The four variables are set to 'Link to: Playmaker Variable' with 'Use PM for initial value?' set to false.

Both playmaker and AC have these four global variables, named identically. Whenever I need AC to sync them with playmaker (to display in inventory etc) I use the Variable: Check action (I believe this is the only way to prompt AC to sync).

In short: held ammo stock and ammo loaded into a weapon are stored in Playmaker global variables. These are sync'd to AC whenever the inventory is opened so ammo counters are displayed correctly in the inventory.

The problem I am having comes when loading a saved game. I am saving the game with 12 pistol bullets in my inventory, the AC global variable for Pistol1Ammo is showing 12 and everything is working as expected prior to loading this save.

When I load that save game (in playmode, after having first ended playmode after the game was saved) my AC global variable for Pistol1Ammo is now showing 0.

I suspect that when loading a save game the save state is loading fine, but the global variables are instantly getting set to those linked in the playable character already present in the scene (with 0 Pistol1Ammo) rather than the values it should be loading from the save file.

I get the impression the Playmaker-AC link is always one-way with playmaker dictating what the AC values are (and those values only updating when a variable-check action is called on them). I have designed my system around this fact but it seems to be an issue when loading an AC save file.

I hope that makes sense, its a complex system to explain. I'm not sure what a suitable workaround here would be. Maybe I need to bite the bullet and rely on something like EasySave to store my playmaker variables when saving/loading?

Many thanks

Comments

  • After hours of messing around with this I came to the conclusion that whilst you are able to sync playmaker global variables to AC ones, you will still need to make a custom remember script to save/load the playmaker variables themselves, otherwise there will be issues with playmaker conflicting when loading AC save games.

    I have made a very barebones remember script for testing purposes, it is currently hardwired for my Pistol1Ammo variable but with some modification I assume this will be helpful for others using Playmaker with AC.

    Remember FSM Variables Script:

    https://pastebin.com/zen2vTs9

  • Thanks for the details. If the workaround works, you might prefer to leave as-is, but PM-linked variables should be saved correctly.

    PM-linked variables should get saved/loaded as normal - it sounds like a case of them being overridden by PM after loading.

    Whenever I need AC to sync them with playmaker (to display in inventory etc) I use the Variable: Check action (I believe this is the only way to prompt AC to sync).

    For a two-way sync to be established, AC will transfer a variable's value to/from PM when requested - as opposed to every frame. That way, it knows which way to transfer the value.

    This is handled automatically when using Actions, but can also be done through script.

    Here's a test script to try: Attach it to your project's PersistentEngine prefab so that it's always present. Does it fix the problem, avoiding the need for a custom Remember script?

    using UnityEngine;
    using AC;
    
    public class VariableLinkTest : MonoBehaviour
    {
    
        private void OnEnable () { EventManager.OnVariableChange += OnVariableChange; }
        private void OnDisable () { EventManager.OnVariableChange -= OnVariableChange; }
    
        private void OnVariableChange (GVar variable)
        {
            if (variable.link == VarLink.PlaymakerVariable) variable.Upload ();
        }
    
    }
    
  • Hey Chris, thanks for taking the time to look into this. Your script does indeed work, variables are saving and loading correctly.

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.