Forum rules - please read before posting.

Hotspot Detection Method not switching properly via code.

Unity 2021.3.5f1
Adventure Creator 1.79.3

I've got code in my game that allows players two hot swap between controller/keyboard and point and click with the mouse. In an effort to make sure I'm setting up the basics for the game properly, I wanted to ensure that hotspot detection would swap between HotspotDetection.MouseOver and HotspotDetection.PlayerVicinity along with all of the juggling I've done with direct input.

The problem is, my code only switched HotspotDetection one way - to MouseOver. All of the other switching code works fine - menus swap between direct and point/click, debug messages are firing indicating everything is fine, and if I start in Direct input mode with Player Vicinity as the Hotspot Detection method, it works fine. Then I click with the mouse, and it switches to MouseOver fine. I can even see it switch in the AC Settings Manager panel. But when I go back to using the controller... HotspotDetection stays on MouseOver.

No debug errors at all. Note: EVERYTHING else works, including switching to MouseOver. It just doesn't pick up the switch back to PlayerVicinity.

Am I missing something in my code? It seems like AC.KickStarter.settingsManager.hotspotDetection = HotspotDetection.PlayerVicinity just doesn't wanna go.

Here's the relevant snippet:

private void OnGUI ()
    {
        Event currentEvent = Event.current;
        if (currentEvent != null)
        {
            switch (currentEvent.type)
            {
                case EventType.Repaint:
                case EventType.Layout:
                    return;

                default:
                    break;
            }

            if (currentEvent.keyCode == KeyCode.Escape)
            {
                return;
            }

            if (currentEvent.isMouse)
            {
                Debug.Log ("Switch to mouse input. Event type: " + currentEvent.type);
                SetInputMethod (InputMethod.MouseAndKeyboard);
                AC.KickStarter.settingsManager.movementMethod = MovementMethod.PointAndClick;
                AC.KickStarter.cursorManager.allowMainCursor = true;
                AC.KickStarter.settingsManager.hotspotDetection = HotspotDetection.MouseOver;
            }

            else
            {

                Debug.Log ("Switch to direct input. Event type: " + currentEvent.type + ", Keycode: " + currentEvent.keyCode);
                SetInputMethod (InputMethod.KeyboardOrController);
                AC.KickStarter.settingsManager.movementMethod = MovementMethod.Direct;
                AC.KickStarter.cursorManager.allowMainCursor = false;
                AC.KickStarter.settingsManager.hotspotDetection = HotspotDetection.PlayerVicinity;
            }
        }

Comments

  • Nevermind, found the problem. Edge case issue where my test method wasn't fully handled by other code. Please feel free to ignore this.

  • That aside, why is it that on PlayerVicinity the icons appear in the middle of the screen rather than over the hotspot? They're properly placed with MouseOver, but on Vicinity it's dead center of the screen.

    https://imgur.com/a/lU0mcNk

  • edited March 4

    The detection method is independent of icon display.

    Check the Hotspot menu's Position field - if set to Follow Cursor, and your cursor is locked in the centre, then it'll appear in the centre as well.

    You can set it instead to On Hotspot to show above the relevant Hotspot.

    If the icon showing is actually the cursor icon, this is separate to the Hotspot icon configured in the Settings Manager. You can prevent the cursor showing Hotspot icons within the Cursor Manager - though the exact field depends on your chosen "Interaction method".

  • Ahh, gotcha! I was looking in all the wrong places to affect it. Hadn't noticed the follow cursor setting.

    Thanks!
  • Okay, I'm feeling stupid about this. I've done what I can based on what I can see in the manual and other forum posts here, but only the label seems to snap to the hotspot, not the icon.

    Here are my settings:

    Interface Settings (under Settings):

    • Movement method: Direct
    • Input method: Controller or Keyboard
    • Interaction Method: Context Sensitive
    • Hide Cursor when locked in screen's centre is checked.

    Hotspot Settings (under Settings):

    • Detection method is Vicinity
    • Hotspots in vicinity: nearest only
    • Display Hotspot Icons: Only When Highlighting
    • Hotspot Icon type: Use Icon

    Menu Settings for Hotspot element:

    • Appear Type: On Hotspot
    • Position: On Hotspot

    Cursor settings:

    • Display Cursor: Always.
    • Change cursor based on Interaction is checked.

    I have this hotspot set to show a Look At icon, and once the Examine interaction is done, the Actionlist turns off the Look At interaction and turns on a Use interaction, resulting in this interestingly doubled up set of use icons:

  • The icon on the right, under the Hotspot label, is the "Hotspot icon". The one in the centre looks to be that of the cursor.

    Though the cursor is set to be hidden when locked, is it actually locked? It's default state is set by the Lock cursor in screen's centre when game begins?, but it can be unlocked at runtime either through the ToggleCursor input, or with the Player: Constrain Action.

    Having the cursor itself switch its icon to that of the Hotspot icon is also a separate option - independent of its visibility. If you're using Context Sensitive interactions, you can uncheck Change cursor based on Interaction? in the Cursor Manager to prevent it showing the Use icon when a Hotspot is selected.

    Otherwise, it's probably best to see screenshots of your Settings and Cursor Managers so that I can see the exact settings you've got.

  • I set Lock Cursor in Screen's Centre, and unchecked Change Cursor based on interaction. I also reset the hotspot icon type back to Texture. This seems to have removed all hotspot icons when playing via direct input.

    So here are my settings, cuz I want to know what I've messed up.

    Here's the scene:

    Settings 1:

    Settings2:

    Settings 3:

    Settings 4:

  • Your Hotspot icon type field is set to Texture, but no Texture is supplied underneath.

    You can either assign an asset in the Hotspot icon texture field, or set the above field to Use Icon to have it rely on the Hotspot's first-available Use icon texture.

  • Well, that did it. Some combo of using Use Icon with the rest of my settings made it work properly. I suspect I was setting more than one setting at a time.

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.