Forum rules - please read before posting.

Enable/Disable Hotspot bug

edited May 2023 in Technical Q&A

I'm not sure whether this has always been an issue, or if it was recently introduced, but I've only noticed it now. I'll give you an example:

I have an an actionlist called "Throw corn" that makes a farmer NPC walk to a marker, play a few animations (he swings his arm, and the corn is scattered all over the ground), and then it runs another actionlist called "Chicken eat corn". This second actionlist tells 3 different chicken NPCs to pathfind to the corn markers, play eating animations, move on to the next markers, etc. Those two actionlists are set to play in the background, and they are triggered by the NPC schedule.

If the player has expressed interest in learning how to feed the chickens before (or if the player interacts with the farmer right before it's time to feed them), then I run a gameplay blocking cutscene where the player and the farmer have a conversation, and between dialogue lines, I trigger the above actionlists so the feeding happens while they talk. This works well!

So, I want the farmer NPC to be able to be interacted with most of the time, but I was finding it pretty finicky to code what happens if the player interacts with him while "Throw corn" is running. So I just figured I'd add a "Disable hotspot" action right at the beginning of "Throw corn", and an "Enable hotspot" one at the end. The player would then only be able to start a conversation with him between 2 throws, but not DURING the throwing.

However, this is breaking my actionlists entirely. It's hard to know when or where they are breaking. Sometimes the farmer stops with his arm raised mid-throw, and the corn never leaves his hands. Sometimes the throw is completed, but the chickens never pathfind to the corn. All I know is that none of this happens if I don't use the "Disable/enable hotspot" actions.

And I also know that this generally happens when those actions are running during the little "tutorial" scene I described, but as far as I can tell not when the farmer is just feeding the chickens in the background as per his schedule. To make sure the schedule wasn't 'competing' with the tutorial triggering of those actionlists, I introduced checks to make sure they only run if they are not already running (didn't help).

I initially thought this had something to do with this modification I'd made to the ActionHotspotEnable.cs action:

        protected void DoChange (Hotspot _hotspot)
        {
            if (changeType == ChangeType.Enable)
            {
                _hotspot.TurnOn ();
            }
            else
            {
                _hotspot.TurnOff ();
                AC.KickStarter.playerInteraction.StopMovingToHotspot();
            }
        }

But even if i comment out the line I added, the issues I described above still happen.

Btw, that line was added so that if the player is pathfinding to interact with a hotspot, and the hotspot is turned off in the middle of the way, the interaction should be cancelled.

The only issue the custom line is causing now is that if the player is told to pathfind to a marker during a cutscene (nothing to do with a hotspot interaction), the pathfinding will be cancelled when a hotspot is disabled, which I believe shouldn't be happening.

Do you have any idea why this could be happening? I'm a bit stumped and don't have much of a lead here.

Comments

  • edited May 2023

    READ THIS FIRST!

    I couldn't edit this post in time. I tried deleting it because I made a mistake and was running the same actionlist twice, even though I thought I'd introduced checks to prevent this. Sorry!

  • edited May 2023

    Also, if anyone is looking to modify their ActionHotspotEnable.cs action so that turning off a hotspot cancels the pending interaction ONLY with that hotspot, this is the way to do it:

            protected void DoChange (Hotspot _hotspot)
            {
                if (changeType == ChangeType.Enable)
                {
                    _hotspot.TurnOn ();
                }
                else
                {
                    _hotspot.TurnOff ();
    
                    if (AC.KickStarter.playerInteraction.GetHotspotMovingTo() == _hotspot)
                    {
                        AC.KickStarter.playerInteraction.StopMovingToHotspot();
                    }
    
                }
            }
    

    If you don't include that condition, AC.KickStarter.playerInteraction.StopMovingToHotspot(); will cancel all pending interactions, and also stop any pathfinding the player is doing, including regular point & click movement and unrelated "move to marker" actions.

  • As an alternative to modifying the Action, you can hook into the OnHotspotTurnOff event, which will fire regardless of how the Hotspot was disabled:

    private void OnEnable () { EventManager.OnHotspotTurnOff += OnHotspotTurnOff; }
    private void OnDisable () {EventManager.OnHotspotTurnOff -= OnHotspotTurnOff; }
    
    private void OnHotspotTurnOff (Hotspot hotspot)
    {
        if (AC.KickStarter.playerInteraction.GetHotspotMovingTo() == hotspot)
        {
            AC.KickStarter.playerInteraction.StopMovingToHotspot();
        }
    }
    
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.