Forum rules - please read before posting.

Interaction Menu on NPC

I cannot, for the life of me, get an interaction menu to appear on an NPC. I've remade my NPC several times, tried it in different scenes, but no luck.

My project is 2D, direct input, hotspot vicinity. I want the game to be playable with only keyboard/controller. So when a character walks up to any hotspot, it shows the hotspot name and icons for the interactions available. All of this works just fine for regular hotspots/objects, but not NPCs.

To open the hotspot's interactions menu, I have this script:

using UnityEngine;
using AC;

public class InteractionOnNearest : MonoBehaviour
{

    public float minimumSqrDistance = 10f;


    private void Update()
    {
        // Check if there is a player with a hotspot detector
        if (KickStarter.player != null && KickStarter.player.hotspotDetector != null)
        {
            // Read the nearest Hotspot to the detector
            Hotspot nearestHotspot = KickStarter.player.hotspotDetector.NearestHotspot;

            if (nearestHotspot != null && KickStarter.stateHandler.IsInGameplay() && (nearestHotspot.transform.position - KickStarter.player.hotspotDetector.transform.position).sqrMagnitude < minimumSqrDistance)
            {
                // If there is a Hotspot nearby, and it's during gameplay, show Interaction menus for that Hotspot
                KickStarter.playerMenus.EnableInteractionMenus(nearestHotspot);
            }
            else
            {
                // Otherwise, close Interaction menus
                KickStarter.playerMenus.CloseInteractionMenus();
            }
        }

    }

}

Here are my AC settings:

My interactions menu settings:

My hotspot menu settings:

My NPC GameObject:

My NPC Sprite object (inside the gameobject):

But this is all I get when I play. No interaction menu, just the NPC name:

Any help is much appreciated!

Comments

  • Welcome to the community, @calebvetter.

    I've run your script - with Settings Manager to match - in the 2D Demo, and I can't find an issue with NPCs. A Hotspot should work the same regardless of it being part of an NPC, though.

    Temporarily switch your Menu Manager asset file to Default_MenuManager, so that your own isn't a factor.

    It's not clear if this is an issue with the script, the settings, or the way the NPC has been arranged. Does it work if you move the Hotspot and BoxCollider components to the NPC's root? Or is it's position a factor, perhaps? Try moving it to the same position as a Hotspot that is working.

    Have you tried debugging the script to see if the EnableInteractionsMenu function is being correctly called? Assuming it is, it may be that it's being turned off from elsewhere for some reason. As your "Close Interactions with" setting is set to Cursor Leaves Menu Or Hotspot, then AC may be turning it off itself. Setting it to Via Script Only instead should prevent this - though you'd need to incorporate the closing behaviour into your script if so.

  • Oh my gosh. I just figured it out. It was the script. I had "debugged" it, but not well. I was seeing that nearestHotspot was indeed getting set and called it good, but the real problem was the minimumSqrDistance. My scale in this scene is much much larger than the other one, so it wasn't passing the if check.

    Which brings up a quick side question: what's considered a good head-to-toe scale for a character? I'm assuming I'd want to keep it as consistent as possible across scenes.

    Also, thank you for being so active and involved in these forums! Been gleaning tons of great info, most of which was authored by you :)

  • Which brings up a quick side question: what's considered a good head-to-toe scale for a character?

    In terms of pixels, or physical size in the scene? The 2D Demo's Brain2D tries to be a good comparable size to go for - try dropping him in the scene next to yours.

    If you want to change your sprite sizes, you can adjust their "Pixels Per Unit" setting in the sprite Inspector.

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.
Do NOT follow this link or you will be banned from the site!