Forum rules - please read before posting.

Set Parameter to current Actionlist

edited May 2023 in Technical Q&A

Hi,

I'm charging energy for interactions like Look and Use. Energy to deduct is 10. I'm trying to kill the interaction Actionlist if the energy is below 10 and turn on energy menu so the players can purchase more energy. I want to get the currently running interaction Actionlist so that I can kill it inside the useinteraction Actionlist if the energy is low. The useinteraction Actionlist is common to all so I need to get the currently running interaction dynamically. Is there an easy way to get the current interaction or the Actionlist in which these actions are taking place?

Here is a screenshot for better understanding.
https://imgur.com/a/nglIogA

Comments

  • edited May 2023

    You can hook a custom script into the OnHotspotInteract custom event, which is fired whenever a Hotspot is interacted with. The parameters in this event can be used to determine the Interaction ActionList that was run as a result:

    Interaction lastRunInteraction;
    
    void OnEnable () { EventManager.OnHotspotInteract += OnHotspotInteract; }
    void OnDisable () { EventManager.OnHotspotInteract -= OnHotspotInteract; }
    
    void OnHotspotInteract (Hotspot hotspot, AC.Button button)
    {
        lastRunInteraction = button.interaction;
    }
    

    To have this be set to a GameObject parameter in another ActionList, you can similarly hook into the OnBeginActionList event. If you know the ID of the parameter, you can use GetParameter to set its value:

    public ActionListAsset commonAsset;
    public int parameterID;
    private Interaction lastRunInteraction;
    
    void OnEnable ()
    { 
        EventManager.OnHotspotInteract += OnHotspotInteract; 
        EventManager.OnBeginActionList += OnBeginActionList;
    }
    
    void OnDisable () 
    { 
        EventManager.OnHotspotInteract -= OnHotspotInteract; 
        EventManager.OnBeginActionList -= OnBeginActionList;
    }
    
    void OnHotspotInteract (Hotspot hotspot, AC.Button button)
    {
        lastRunInteraction = (button != null) ? button.interaction : null;
    }
    
    void OnBeginActionList (ActionList actionList, ActionListAsset actionListAsset, int startingIndex, bool isSkipping)
    {
        if (actionListAsset && actionListAsset == commonAsset && lastRunInteraction)
        {
            actionList.GetParameter (parameterID).SetValue (lastRunInteraction.gameObject, lastRunInteraction.GetComponent<ConstantID>().constantID);
    
        }
    }
    
  • Hi Chris, I have zero knowledge of C# and this scripts are giving me shivers. Please guide me on where I need to paste the scripts. I tried looking at the CALLING CUSTOM EVENTS page but that too is too complicated for me. Sorry for the trouble.

  • Create a new C# file and paste the second code block inside the body of it (i.e. replacing the Start and Update functions that it defaults with).

  • edited May 2023

    Hi Chris, sorry for not mentioning but I'm using multiple interactions here, Like "Look" "Use" "Examine" Etc.. I might add more in the future. But the code you provided is having only one Common Asset field, where as I might need to use multiple for each interaction.

    But still it's not working as expected when I tried with just the UseInetraction ActionList Asset. I have created a C# script named HotspotInteractionTracker and attached it to a game object in the scene. Then in the Common Asset Field I placed the UseInteraction ActionList Asset. And in the parameterID I copied the Default value (ID #) from the Parameter of that UseInetraction ActionList Asset.

    I'm trying to check the energy value in the UseEnergy ActionList Asset and LookEnergy ActionList Asset and kill the Interaction to Kill parameter inside these ActionList Assets.

    I have also tried to replace the parameterID with the number on the left side of the parameter instead of using the Default value (ID #) but the Interaction ActionList is still not getting killed.

    Here is a screenshot :
    https://imgur.com/a/Unbgbru
    https://imgur.com/a/3hTJBhC
    https://imgur.com/a/UwKHsgX
    https://imgur.com/a/QgOdsYi

  • edited May 2023

    I left the Interaction to Kill parameter in the Interaction ActionList empty because I'm trying to use the script you provided to set the parameter inside the UseInteraction ActionList Asset or LookInteraction ActionList Asset. Am I supposed to do this? Is there a better way to implement this system?

    https://imgur.com/a/jfUX3LW

  • Here is another screenshot which might help in understanding the problem.

    https://imgur.com/a/nyxyFVt

  • sorry for not mentioning but I'm using multiple interactions here,

    Let's get things working with just one first, and then see about others.

    And in the parameterID I copied the Default value (ID #) from the Parameter of that UseInetraction ActionList Asset.

    The "Default value ID" refers to the Constant ID value of the assigned GameObject. You instead need to assign the ID of the parameter - which is to the left of its name further up.

    I've tweaked the code above as well as given it a log in the Console to check what's going on - give it a try now.

  • edited May 2023

    Hi Chris, I've tried the updated code you provided but that is still not killing the Interaction ActionList.

    The Current Value in the Interaction to Kill parameter of the UseInteraction ActionList Asset is empty.

    I have assigned ID of the parameter - which is to the left of its name.

  • Don't check the asset - check the instance of it in the scene.

    What does the Console report at the time?

  • edited May 2023

    I have checked the ActionList Asset at runtime in the scene and the Interaction to Kill parameter is empty.

    Here is the console

    assigned TV: Use (AC.Interaction) to UseInteraction (AC.RuntimeActionList)
    UnityEngine.Debug:Log (object,UnityEngine.Object)

  • Do you think it will be easier to set the lastRunInteraction to a global variable and use that instead?

  • Recreated - my mistake.

    I've corrected the script once more. Also, you will need to ensure that each Interaction ActionList has a Constant ID component attached - since this is how scene-based objects are referenced by ActionList assets.

  • Thank you it is working now. Can I use the same script multiple times for different Interactions?

  • You can, but each instance of the script will affect its own asset.

    It might be OK as it is, though, if you only run ever those assets as a result of interactions in the way your screenshots show.

  • Hi Im getting this error when I interact and using the script you provided.

    NullReferenceException: Object reference not set to an instance of an object
    HotspotInteractionTracker.OnBeginActionList (AC.ActionList actionList, AC.ActionListAsset actionListAsset, System.Int32 startingIndex, System.Boolean isSkipping) (at Assets/MM/HotspotInteractionTracker.cs:33)
    AC.EventManager.Call_OnBeginActionList (AC.ActionList actionList, AC.ActionListAsset actionListAsset, System.Int32 startingIndex, System.Boolean isSkipping) (at Assets/AdventureCreator/Scripts/Managers/EventManager.cs:2235)
    AC.RuntimeActionList.BeginActionList (System.Int32 i, System.Boolean addToSkipQueue) (at Assets/AdventureCreator/Scripts/ActionList/RuntimeActionList.cs:177)
    AC.ActionList.Interact (System.Int32 i, System.Boolean addToSkipQueue) (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:274)
    AC.RuntimeActionList.DownloadActions (AC.ActionListAsset actionListAsset, AC.Conversation endConversation, System.Int32 i, System.Boolean doSkip, System.Boolean addToSkipQueue, System.Boolean dontRun) (at Assets/AdventureCreator/Scripts/ActionList/RuntimeActionList.cs:136)
    AC.AdvGame.RunActionListAsset (AC.ActionListAsset actionListAsset, AC.Conversation endConversation, System.Int32 i, System.Boolean doSkip, System.Boolean addToSkipQueue) (at Assets/AdventureCreator/Scripts/Static/AdvGame.cs:242)
    AC.AdvGame.RunActionListAsset (AC.ActionListAsset actionListAsset, System.Int32 i, System.Boolean addToSkipQueue) (at Assets/AdventureCreator/Scripts/Static/AdvGame.cs:201)
    AC.ActionRunActionList.Run () (at Assets/AdventureCreator/Scripts/Actions/ActionRunActionList.cs:204)
    AC.ActionList+<RunAction>d__45.MoveNext () (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:456)
    UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) (at <bae255e3e08e46f7bc2fbd23dde96338>:0)
    UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator)
    AC.ActionList:ProcessAction(Int32) (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:406)
    AC.ActionList:BeginActionList(Int32, Boolean) (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:373)
    AC.ActionList:Interact(Int32, Boolean) (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:274)
    AC.ActionList:Interact() (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:237)
    AC.<UseObject>d__38:MoveNext() (at Assets/AdventureCreator/Scripts/Controls/PlayerInteraction.cs:1534)
    UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)
    
  • Sorry I forgot to and ConstantID to all the interaction ActionLists. Adding a ConstantID fixed the error. Thank you again.

  • I get this error when using inventory items on hotspots with no respective interaction for that item. Basically it's an Unhandled interaction but there is not interaction in Unhandled interaction for any inventory items.

    NullReferenceException: Object reference not set to an instance of an object
    HotspotInteractionTracker.OnHotspotInteract (AC.Hotspot hotspot, AC.Button button) (at Assets/MM/HotspotInteractionTracker.cs:26)
    AC.EventManager.Call_OnInteractHotspot (AC.Hotspot hotspot, AC.Button button) (at Assets/AdventureCreator/Scripts/Managers/EventManager.cs:405)
    AC.PlayerInteraction.ClickButton (AC.InteractionType _interactionType, System.Int32 selectedCursorID, AC.InvInstance selectedInvInstance, AC.Hotspot clickedHotspot) (at Assets/AdventureCreator/Scripts/Controls/PlayerInteraction.cs:1074)
    AC.PlayerInteraction.HandleInteraction () (at Assets/AdventureCreator/Scripts/Controls/PlayerInteraction.cs:849)
    AC.PlayerInteraction.ChooseHotspotThenInteractionClick_Process (System.Boolean doubleTap) (at Assets/AdventureCreator/Scripts/Controls/PlayerInteraction.cs:502)
    AC.PlayerInteraction.ChooseHotspotThenInteractionClick () (at Assets/AdventureCreator/Scripts/Controls/PlayerInteraction.cs:427)
    AC.PlayerInteraction.HandleInteractionMenu () (at Assets/AdventureCreator/Scripts/Controls/PlayerInteraction.cs:200)
    AC.PlayerInteraction.UpdateInteraction () (at Assets/AdventureCreator/Scripts/Controls/PlayerInteraction.cs:131)
    AC.StateHandler.Update () (at Assets/AdventureCreator/Scripts/Game engine/StateHandler.cs:213)
    
  • I've updated the script once more - give it another try.

  • The error is gone. Thanks.

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.