Forum rules - please read before posting.

Stopping interactions when they are turned off

edited January 2023 in Technical Q&A

I'm having an issue where an NPC is scheduled to go into a house at 5pm. While the NPC is outside, their hotspot and talk interaction are enabled. "Cutscene while moving?" is unchecked, and a minimum distance is set, meaning that if the player interacts from far away, they will pathfind to the NPC before they talk. The player can click away to cancel the interaction before reaching the minimum distance.

So the in-game clock is running, it's nearly 5pm, and from far away the player interacts with the NPC. While the player is pathfinding to the NPC location, another actionlist will fire at 5pm, disabling the NPC's hotspot/interactions, and making it walk towards the door, open it and be teleported out of view. Just before the NPC is teleported out, the player reaches the minimum distance, causing the talk interaction to run. The NPC has been teleported out, their hotspot has been disabled, but the dialogue still runs.

Would it be possible to include a check when the player reaches the minimum distance that will stop the interaction from running if the hotspot/interaction has since been disabled? Or perhaps the disable action itself could cancel the pathfinding/pending interaction?


  • Possibly - I'll attempt a recreation, thanks for the details.

    Either way, it's possible to cancel the "pending" interaction by calling the PlayerInteraction script's StopMovingToHotspot function:

    AC.KickStarter.playerInteraction.StopMovingToHotspot ();
  • edited January 2023

    Thanks! Changing ActionHotspotEnable.cs seems to have done the trick:

            protected void DoChange (Hotspot _hotspot)
                if (changeType == ChangeType.Enable)
                    _hotspot.TurnOn ();
                    _hotspot.TurnOff ();

    Also, something I've noticed is that if the player is moving to the hotspot and then the hotspot changes places (for example, if it's a child of a walking NPC), the player will pathfind to the point where the hotspot was when it was interacted with, not where it currently is.

  • You may be able to remedy that by setting a non-zero Pathfind update time (s) value in the Settings Manager, and then have the Hotspot's Player action set to Walk To Marker.

    If so, it may then have to be a case of dynamically altering the Marker's position relative to the NPC.

  • Hm, I've done this, and it doesn't work. From what I can see, point-and-click character movement works by producing a path via the Paths component attached to the player. It looks like the same happens when you interact with a hotspot: AC checks the location of the marker, creates a path to that location, and tells the player to follow it. Even if you set a non-zero Pathfind Update Time, the path nodes stored by the Paths component remain the same until the player reaches the last node. The location of the marker is only checked once when producing the path.

    But even if it did work, using "Walk to Marker" doesn't allow you to set a minimum distance and a proximity value, so the player would stand on top of the NPC when talking, which isn't ideal. A solution would need to take that into account.

  • That's what I was getting at re: dynamically altering the Marker's position.

    You're right that the pathfind updating doesn't affect things, however. This is likely best addressed by introducing a custom event hook that allows you to alter the destination when this occurs, so that the Player could be re-directed to the Hotspot's new position. This should be able to work regardless of the WalkTo / WalkToMarker option.

  • Ah, right, I get what you mean now.

    An event hook sounds like a good idea! So through this hook we could run a script that checked whether the path destination was still the same as the hotspot's location every 0.5s (or whatever value worked best), and if different, recalculated the path?

  • That's right - though AC should feasibly be able to hook into this same event to do this automatically.

  • I've just tested this change, and I think there's a small glitch in the process.

    Using the "Walk to" hotspot option and a non-zero pathfind update time, the player will correctly pathfind to the hotspot child of the moving NPC. You can see the path being recalculated in the Scene window if you select the Player game object.

    The issue is that the point where the interaction is triggered remains the same. If the NPC is moving towards the player, then the player never reaches that spot and continues going after the NPC. But if the NPC is moving away from the player, then the player reaches the interaction spot before they reach the NPC, and the interaction is triggered. Like this:

  • OK, thanks for the details - I'll look into it.

  • Recreated. To fix, open the PlayerInteraction script and replace line 1345:

    while ((KickStarter.player.Transform.position - targetPos).sqrMagnitude > proxSqrd && KickStarter.player.GetPath ())


    while (KickStarter.player.GetPath () && (KickStarter.player.Transform.position - KickStarter.player.GetPath ().Destination).sqrMagnitude > proxSqrd)
  • Perfect! Just tested this. Thank you.

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.