Forum rules - please read before posting.

Direct Movement\Point and Click hybrid: issues with switching Hotspot Detection via script

edited July 2020 in Technical Q&A

[Unity 2019.4.1f1 - AC 1.71.5]

Hello!

I'm trying to make both Direct Movement and Point and Click available to players, with a different Hotspot Detection: respectively HotspotDetection.PlayerVicinity and HotspotDetection.MouseOver.

I have a tiny script running in an Update() function attached to my Player.

if (State == ControlState.POINT_CLICK)
{
    if (KickStarter.playerInput.GetMoveKeys() != Vector2.zero)
    {
        AC.KickStarter.player.Halt();
        AC.KickStarter.settingsManager.movementMethod = MovementMethod.Direct;
        AC.KickStarter.settingsManager.hotspotDetection = HotspotDetection.PlayerVicinity;

        State = ControlState.DIRECT;
    }
}
else if (State == ControlState.DIRECT)
{
    if (KickStarter.playerInput.GetMoveKeys() == Vector2.zero && Mouse.current.wasUpdatedThisFrame)
    {
        AC.KickStarter.settingsManager.movementMethod = MovementMethod.PointAndClick;
        AC.KickStarter.settingsManager.hotspotDetection = HotspotDetection.MouseOver;

        State = ControlState.POINT_CLICK;
    }
}

(ControlState is just a pretty basic enum I'm using)

So, basically whenever I switch controls, it switches Movement Method.

Starting from Point and Click it almost works: moving my mouse around on hotspots the related UI will show up accordingly (for completeness, it's Appear Type is set to On Hotspot), then when I start moving with a controller, it switches correctly to PlayerVicinity.

On the contrary, when I go back to moving my mouse (so from Direct Movement, back to Point and Click), when I hover with the mouse the Hotspot UI wont show up.

I'm tracking the state of AC.KickStarter.settingsManager.hotspotDetection and AC.PlayerMenus.GetMenuWithName("Hotspot").IsOn() with Debug.Log()s so I can tell that the switch executes successfully, but when I'm back into Point and Click mode, the "Hotspot" Menu won't turn on.

Is there anything I'm missing or doing wrong?

Thanks in advance!

EDIT: I forgot to mention this! Although I'm using the new Unity Input System, my Active Input Handling is set to Both.

Comments

  • You shouldn't have to rely on an internal "ControlState" enum. To make sure you're always synced with AC, read instead the value of AC's movementMethod variable to be sure the correct code block is always run, i.e.:

    if (AC.KickStarter.settingsManager.movementMethod == MovementMethod.Direct) { /*... */ }
    

    Sounds like it should work, though. What state is the Player in when switching from Direct to Point And Click? Check that this occurs when you're not already interacting with a Hotspot / moving towards it at that moment.

    Is the Hotspot still interactive despite the menu not showing up? Temporarily assign an "Object to highlight" if it doesn't have one already - does that show up even if the Hotspot menu itself does not?

    Let's see a shot of your Settings Managers, and the Hotspot menu's properties.

  • edited July 2020

    Is the Hotspot still interactive despite the menu not showing up?

    I think this led me to find the issue (or at least part of it).

    When switching from Point and Click to Direct the Hotspots' GameObjects in the scene change Layer, going from Default to DistantHostpot, and don't change back when I switch again.

    So yeah, it indeed becomes non interactive when using the mouse (except if I hover it while the Player is still colliding with its BoxCollider2D).

    If I manually set them back to the Default Layer, the mouse will find them again and interact with them again.

    So the solution seems either to be sure that, when you're in Direct mode and the Hotspot Detection method is set to Player Vicinity, the Place distant Hotspots on a separate layer is unticked, or that you switch the Hotspots' Layers at runtime?

    Anyway: here are the screenshots of my Settings Manager!

    When in Point and Click mode:



    When in Direct mode:



    Among other things I wanted also to try switching Input method between the two, having Keyboard or Controller when in Direct mode.

  • Yes, it would be easiest to just uncheck Place distant Hotspots on a separate layer? - this is what makes use of the "DistantHotspot" layer.

  • Thanks! I will just stick to this, then. Hopefully it doesn't turn against me in the long run :smiley:

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.