Forum rules - please read before posting.

Cancelling unhandled action using hotspot as substitute for move to marker doesn't stop actionlist?

edited October 2019 in Technical Q&A

I'm using a dynamic "move to point" hotspot so that unhandled interactions can have the player walk to them first before the dialogue telling the player the hotspot it can't be used:

Unfortunately, if the "walk to" is cancelled before reaching the hotspot, the player will still say the line of dialogue. Is there a way of forcing the whole actionlist to be cancelled if the walk to is intercepted?

Comments

  • You can hook into the OnCharacterEndPath custom event to kill the ActionList asset:

    using UnityEngine;
    using AC;
    
    public class CancelActionListExample : MonoBehaviour
    {
    
        public ActionListAsset assetToCancel;
    
        private void OnEnable ()
        {
            EventManager.OnCharacterEndPath += OnEndPath;
        }
    
        private void OnDisable ()
        {
            EventManager.OnCharacterEndPath -= OnEndPath;
        }
    
        private void OnEndPath (Char character, Paths path)
        {
            if (character.IsPlayer)
            {
                assetToCancel.KillAllInstances ();
            }
        }
    
    }
    
  • I just added this as a script on my custom scene scripts objects, and if I cancel an unhandled interaction, the character still speaks, is this script meant to work for all actionlists, even unhandled ones?

  • It should kick in for whatever ActionList asset you assign in its Inspector. Try placing in a Debug.Log statement above the KillAllInstances line, i.e.:

    Debug.Log ("Player stopped moving");
    
  • Would I need to modify the script so it cancels any actionlist that's running? It wouldn't be for one particular actionlist, rather for all of the unhandled actionlists that don't kill the whole list when it's cancelled by clicking away.

  • For multiple ActionLists, you can rely on an array instead:

    using UnityEngine;
    using AC;
    
    public class CancelActionListExample : MonoBehaviour
    {
    
        public ActionListAsset[] assetsToCancel;
    
        private void OnEnable ()
        {
            EventManager.OnCharacterEndPath += OnEndPath;
        }
    
        private void OnDisable ()
        {
            EventManager.OnCharacterEndPath -= OnEndPath;
        }
    
        private void OnEndPath (Char character, Paths path)
        {
            if (character.IsPlayer)
            {
                foreach (ActionListAsset assetToCancel in assetsToCancel)
                {
                    assetToCancel.KillAllInstances ();
                }
            }
        }
    
    }
    
  • Adding the unhandled open actionlist in the array cancels the actionlist when the player reaches the door and doesn't play the "I can't open that" dialogue. Should it be cancelling prematurely?

  • Ah, I was being stupid. This will cancel the ActionLists whenever the Player stops moving, even if it's part of the original interaction.

    Let's try hooking into OnCharacterSetPath to record the player's destination. If he's not within a certain distance from it when the path ends, it should be safe to assume it's been cancelled:

    using UnityEngine;
    using AC;
    
    public class CancelActionListExample : MonoBehaviour
    {
    
        public ActionListAsset[] assetsToCancel;
        public float distanceThreshold = 0.1f;
        private Vector3 destination;
    
        private void OnEnable ()
        {
            EventManager.OnCharacterSetPath += OnSetPath;
            EventManager.OnCharacterEndPath += OnEndPath;
        }
    
        private void OnDisable ()
        {
            EventManager.OnCharacterSetPath -= OnSetPath;
            EventManager.OnCharacterEndPath -= OnEndPath;
        }
    
        private void OnSetPath (Char character, Paths path)
        {
            if (character.IsPlayer)
            {
                destination = character.GetTargetPosition (true);
            }
        }
    
        private void OnEndPath (Char character, Paths path)
        {
            if (character.IsPlayer && Vector3.Distance (character.transform.position, destination) > distanceThreshold)
            {
                foreach (ActionListAsset assetToCancel in assetsToCancel)
                {
                    assetToCancel.KillAllInstances ();
                }
            }
        }
    
    }
    
  • I'm using it with Close_Unhandled_Interaction and no matter what distance I set, it still plays the dialogue if action is cancelled. What method is used to cancel "walk to marker" interactions? In the case of unhandled interactions, the use of move to (hotspot) point is necessary because "walk to marker" can't be used for unhandled interactions (since they haven't been set anywhere) could there be a way to use "walk to marker" for all unhandled interactions before the "i can't close/open/use that" dialogue in the unhandled actionlist is shown?. If not, is there some reason this distance float isn't working as intended?

  • Perhaps this is the wrong approach.

    could there be a way to use "walk to marker" for all unhandled interactions before the "i can't close/open/use that" dialogue in the unhandled actionlist is shown?

    I shall consider.

  • Thank you so much, it would be greatly appreciated! That way all interactions can be handled similarly and I can keep unhandled actionlists just containing the "I can't do that" dialogue and the sentence would hopefully stick during the "walk to" as it does with handled interactions.

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.