Forum rules - please read before posting.

LocalVariables.GetAllVars returns 0 entries.

Hello!

So, I'm working with AC for a client. I'm handling all the serialisation stuff. We're using our own system for the saving/loading due to need for console support etc. It's all pretty straight forward so far.

The thing that I'm struggling to work out at the minute is that LocalVariables.GetAllVars() is returning 0 results. What I'm thinking is causing the issue is that we're not using AC's scene loading, but handling it ourselves - so I'm thinking whatever tells AC of the scene we're currently in isn't being set correctly.

On the flip side, Action scripts to set a local variable is working correctly and the varibale is being set (and queried correctly from an Action script to determine dialogue choices), it's just not returning anything when using LocalVariables.GetAllVars(). I've tried Kickstarter.sceneChange.AddSubScene and passing a new SceneInfo with the scene name and index, but that doesn't seem to do anything.

When querying the subscenes that are loaded (I don't know if this is the right place to look tbh), it's showing the currently loaded scene. If I look in the GameEditor when the scene is open, the local variables list is empty, but it shows local variables if I just manually open the scene in the editor. So my initial thought of whatever loads/refresh LocalVariables doesn't know what scene we're in looks increasingly less likely to be the problem...

Any pointers on what I might be missing would be much appreciated!

Thanks!

Comments

  • Welcome to the community, @MoonWizard.

    The LocalVariables.GetAllVars() method is a static one made for convenience.  It's actually shorthand for:

    KickStarter.localVariables.localVars;

    If you're getting a NRE with that, then it's likely that the KickStarter's localVariables variable is not being set correctly.  The KickStarter script caches all of AC's engine components - which should be automatic and based on the "main" scene if multiple are open.  Normally such problems shouldn't arise so long as your active scene contains a KickStarter component.

    You could try placing Debug.Log statements in KickStarter's SetGameEngine method to see what's going on.

    I would, however, expect much more problems if you do not load scenes via AC - since AC does a lot of necessary tasks internally when changing scene.  Through script, the correct way to change scene is with:

    SceneInfo nextSceneInfo = new SceneInfo ("MyScene");
    KickStarter.sceneChanger.ChangeScene (nextSceneInfo, true);

    You haven't shared much detail so far as what exactly you're doing and why, but it is worth noting that custom scene-loading should not be necessary to get the save system working on consoles - just implementing a new format / location as per the docs should be enough.
  • Hi @ChrisIceBox !

    Thanks for the reply. I've been away for a few days so I'm only just getting around to checking out your reply. 

    AC is being used for the game, alongside development of an overall framework for future games. AC is perfect for structuring this particular project in terms of level design etc, but we need to decouple as much as possible so it's not too tighlty linked to AC for future projects which possibly won't use AC...

    ANYWAY..

    So that was a super helpful post, as it's helped me understand how AC works a little better. 

    Currently there is one 'main' / core scene that persists throughout the project, this currently has all the AC required scripts etc. I've noticed that the 'level' scenes we are additively loading in  alongside the main scene also has a GameEngine, but it gets Deactivated on load. The 'Active' scene is still the original one, rather than the new 'level' scene. I joined the project after development started. It might be that they adjusted stuff here and there may be a reason everything tries to reference the original AC stuff in our core scene, I'll investigate this.

    One quick question - if there are 2 game engines, is it normal for the second game enging to just deactivate itself if another exists?

    Either way, it seems as though this could be the reason no local vars are being loaded if the Game Engine on the scene we are loading (that has local variables defined in the AC game editor) is neither the active scene within Unity and has the Game Engine deactivated...?







    • if there are 2 game engines, is it normal for the second game enging to just deactivate itself if another exists?
    Yes - both scenes will adopt the settings laid out by the "main" scene's GameEngine, and the sub-scene's GameEngine will be ignored.

    I see what you mean now.  The static "KickStarter.localVariables" refers to the "active" GameEngine's KickStarter component.

    Actions that are placed within the sub-scene are still able to access their own scene's LocalVariables, however - and this can be done through script as well:


    Where "myGameObject" is a reference to a GameObject that exists in the sub-scene.  The method will then refer to that object's scene to retrieve the appropriate LocalVariables component.
  • Okay, fantastic.

    Thanks for that. I'm not back on the project properly until tomorrow but just trying to sort out a solution so I'm ready to hit the ground running tomorrow. That's really helped and should help me fix the issue I'm having.

    Thanks again, and well done with AC, it really is a great product and really powerful!
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.