Forum rules - please read before posting.

Gameobject as a global variable?

Not sure if this is achieved in some other way, but personally I'd find it very useful if you could create a global variable of type Gameobject, or mp3, or any type for that matter.

If would save a lot of time in assigning items based on the integer or Boolean value of a global variable, if you could just drag any unity object to a global variable slot, so you could directly read that back out in actionlists.

Is there any chance of adding this feature or is there a fundamental issue with this?

Cheers
Andi

Comments

  • edited November 2020

    The main technical issue is that of saving changes made to such values at runtime.

    But design wise: variables are primarily for logic building. When it comes to actually changing Actions and Action values themselves, parameters are typically the better option - and these do support GameObject and Unity Object types.

    Can you share more on your specific situation? An add-on helper script may be appropriate here.

  • Hi Chris,

    The particular situation I was thinking of was related to a cutscene narration variable.

    In my game the player can select a location from a map, and in many cases a cutscene is shown driving to the next location with a specific MP3 narration file (based on how far they have progressed on any one track and where they are travelling to)

    It would be nice to have a global, driving narration variable that I can set to a specific MP3 at any point and is always played as part of the driving cutscene, without me having to do lots of switch or check else if statements in an action.

    I might be totally overcomplicating something that is much more easily done another way, I tend to work on this when it's late and I'm not at full brain function. :)

    The added complexity of ensuring I only play the correct narrative if they've completed a particular set of tasks, **and **are travelling to a certain location, from a certain location is bogging me down.

    Given players can visit some of the locations in any order and may (or may not) have uncovered the specific clue that advances the story in that location, there's already lots to check each time they choose a map location. There are even occasions where a stock narration is played if they haven't achieved everything they need to.

    If that makes any sense at all, any suggestions you have to simplify this would be greatly received.

    Thanks for the support.
    Andi

  • It sounds like the bulk of the complexity comes from the logic preceding the actual handling of the MP3 file - i.e. evaluating the current situation to determine what to play.

    If you rely on ActionLists, I expect there's no way around that involving long chains of if/else/switch commands through Actions. Be aware that all of those can be performed in code - and sometimes it's a preferrable approach if the specifics of the situation mean that code would be more manageable.

    For example, this code snippet would check if a Global Boolean variable named "HasCompletedTask" is True, and that the last-visited scene was index 2:

    if (GlobalVariables.GetVariable ("HasCompletedTask").BooleanValue == true &&
        KickStarter.sceneChanger.GetPreviousSceneIndex (true) == 2)
    {
        //
    }
    

    As for the MP3 itself - you can rely on AC's Speech system rather than reference the audio file directly. You can either mark a Dialogue: Play speech Action as narration by not assigning a speaker, or assign an invisible "Driving Narrator" NPC so that you can separate these lines from other narration you may have.

    Once gathered up by the Speech Manager, you can then assign your audio to the narration lines as you would any other voiced speech line. Playing the audio would then just be a case of triggering the speech Action - either by placing it within the same ActionList as the one that handles the logic, or by placing each such line in a separate ActionList asset file. Such an asset could either by run from another ActionList (with ActionList: Run), or through script:

    myActionListAsset.Interact ();
    
  • Thanks so much for your considered and detailed reply, all really helpful and lots of food for thought.

    I think a combination of your suggestions is the ideal path for me, to cut down the amount of wiring required in my map action lists and provide a more extendable solution as the map locations increase and logic checks get more convoluted.

    Thanks again, much appreciated!
    Andi

  • Sorry for highjacking/necroing this thread, but I'd also like to "bump" this request from andi.

    In my own case, I've found myself in the need of changing numerous navmeshes, as I don't want to load a new scene just for changing the background location.

    I use prefabs for those scenes, and they have their nav meshes inside the prefab, which could also have various versions. One is chosen to be enabled depending on that context.

    So, seeing that the final step for correctly changing the nav mesh means running the appropriate action, I made a scene action list with a game object parameter that should have got it from a connected PlayMaker global variable, changed in turn by the chosen nav mesh object's PlayMaker FSM.

    That would have been very straightforward, but I've found out that there's no support for game object variables, nor global or local.

    Then, searching the forums I've seen you don't seem willing to add support for game objects variables. Mainly because you consider there are other ways to do this.

    Don't get me wrong and think I'm blind to your efforts and ungrateful. AC is certainly great and you've been improving it for years.

    But there's also one truth here that you're not taking into account enough...: many of your users are not programmers, and we need extra flexibility in finding paths to reach Rome.

    I'm sure there must be a way to set a GO parameter, without manually referencing it with another action (which beats the purpose of trying to automate this), but it's not an obvious one. It must imply scripting and delving into code.

    In short, regarless of those "correct" ways of doing this, could you reconsider adding game object variables, please?

  • edited January 2021

    With or without such a feature, I am here to assist if scripting is necessary.

    Variables in AC are chiefly used for logic processing. GameObjects are more useful as parameters, in that they can then be used to affect Actions.

    Are you looking to transfer a PM GameObject variable to an AC GameObject parameter? How are you looking to use such a variable/parameter in your ActionList?

    I need to see the specific situation where such a feature would potentially be used. Can you elaborate, with screenshots, on the NavMesh situation you describe?

  • Of course.

    I have these "scene" prefabs...

    Not Unity scenes, but "rooms" that I exchange when the MC moves to another location.

    It has the images and geometry needed for both Direct (physical colliders) and Point & Click (navmesh with hole) movement.

    Having the "local" navmesh inside the prefab, apart from being cleaner, allows me to change the default navmesh when instantiating the whole thing, which is more straightforward than managing them in the scene.

    So, I made this Action List Asset...:

    ...and on each navmesh game object I added this:

    The local parameter default value "NavMesh" is the result of dragging its own GO to the field.

    Of course it works, and I guess this is the recommended procedure to follow (?).

    However, I think this could be improved in two ways...:

    1. Adding a "set owner" option to the Set Parameter action:

    That would eliminate the need to drag the owner GO to the field, each time I create a navmesh.

    1. Being able to reference an AC global game object variable:

    We can't because AC game object variables don't exist.

    However, if they did, I could use a PlayMaker global variable to handle which navmesh should be activated at each moment. Something I would very much prefer, to delegate on a centralized PlayMaker FSM, instead of depending on several action lists with manually introduced local parameters.

    Solution 1 would be very nice to have, yes. I'd still humbly suggest you add that, if you could.

    But the main reason I ask for game object variables support is so we can also have the flexibility to do things in different ways. All roads should lead to Rome, let's say.

    Also, note I didn't ask for those game object variables being able to be saved with AC save system. I don't need a Remember GameObject component for this working as I say.

    Again, don't get me wrong because I love AC, but I also think depending so heavily on just one way of doing things is no good... :/

  • Thank you for the elaboration.

    Your feedback is noted and I will take it into account.

    Though, I would say that in your provided example, you're looking to use GO variables as a middle-man between a GO parameter and a PM variable. It's entirely possible to sync a GO parameter with a PM variable directly, using a custom script:

    using UnityEngine;
    using HutongGames.PlayMaker;
    using AC;
    
    public class SyncPMAndParameterGO : MonoBehaviour
    {
    
        public ActionListAsset myAsset;
        public string pmGlobalVariableName;
        public int parameterID;
    
        private void OnEnable () { EventManager.OnBeginActionList += OnBeginActionList; }
        private void OnDisable () { EventManager.OnBeginActionList -= OnBeginActionList; }
    
        private void OnBeginActionList (ActionList actionList, ActionListAsset actionListAsset, int startingIndex, bool isSkipping)
        {
            if (actionListAsset == myAsset)
            {
                FsmGameObject fsmGO = FsmVariables.GlobalVariables.FindFsmGameObject (pmGlobalVariableName);
                if (fsmGO != null)
                {
                    actionList.GetParameter (parameterID).SetValue (fsmGO.Value);
                }
            }
        }
    
    }
    
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.