Forum rules - please read before posting.

Simulated Cursor doesn't Display

Hi,

I've been looking around the forums for a solution for hours but nothing seems to work.

I have a initial proto where I'm directly controlling the player. I set up a controller key to open the inventory and directly control it. I can drag items around the inventory and I see them disappear from one spot and appear in the next.

The simulated cursor doesn't appear while dragging stuff. In fact I can never control the cursor with the gamepad.

I am using the Unity UI system. Any ideas pls?

Much appreciated, thank you.

Comments

  • My intention is to recreate the interaction method from Roki where you can use the controller to select an inventory item and drag it to a hotspot with a visual cursor showing that item

  • Welcome to the community, @mibwab.

    What are your AC and Unity versions, and is the simulated cursor showing up by default - or do you have Lock cursor in screen's centre when game begins? checked in the Settings Manager.

    Is your game paused while the Inventory menu is open, such that Directly-navigate Menus when paused? is checked in the Menu Manager - or are you using the Engine: Manage systems Action to directly-navigate it during gameplay?

    It might be a case of having to alter some fields through script as an item becomes selected - but I'll need to know the specifics of your set up first.

    If possible, it'd be best to see screenshots of your Settings, Cursor and Menu Managers - with the Inventory menu selected - along with any ActionLists that deal with the display of the Inventory menu. With those, I should be able to recreate your issue and suggest steps to go forward.

  • edited May 2023

    Hi Chris, thanks a lot for the quick response.

    Unity: 2021.3.21f1
    AC v1.77.0

    The cursor shows up in the middle of the screen but I cannot move it. Posting a screenshot and video here:
    https://www.dropbox.com/s/gb4cqpylqqzyd7e/AC_1.png?dl=0

    Video of current behavior

    Desired behavior for drag-and-drop item from inventory to hotspot

    I haven't set up any engine actions or action lists.
    Thanks again for your help

    Settings
    https://www.dropbox.com/s/j4udk43mmsjnt63/Settings.jpg?dl=0

    Cursor
    https://www.dropbox.com/s/apho1gl20ggx3a6/cursor.jpg?dl=0

    Menu Manager
    https://www.dropbox.com/s/751fge7tamqmsji/menu.jpg?dl=0

  • I'd like to also note the cursor doesn't seem to appear when dragging items even though I can drag them in the inventory at least

  • OK. This'll be a little complex, as there are a few settings involved - as well as a little bit of custom scripting. It might take a bit of tweaking to make things perfect, but this should get us most of the way there:

    First, go to your Settings Manager and check Lock cursor in screen's centre when game begins? and Hide cursor when locked in screen's centre?. Further down under "Inventory settings", check Drag and drop interface?. In "Hotspot settings", uncheck Place Hotspots on separate layer?.

    In your Menu Manager, uncheck the Inventory menu's Pause game when enabled? property - to be exactly like Roki, we'll want gameplay to continue while the Inventory menu is shown.

    Because of this, though, we'll need to make some adjustments to the game when Inventory turns on. To do this, click the "+" icon beside its ActionList when turn on field to create a new ActionList asset that will run at this time.

    Inside this asset, create an Engine: Manage systems Action that disables Movement, and enables Direct-nav in-game Menus. This will stop the Player from moving, and also allow direct navigation of the Menu.

    You'll then need to repeat this process for the opposite - i.e. create an "ActionList when turn off" that re-enables movement / disables direct-navigation.

    To move the cursor, you'll need to define inputs in your Input Manager named "CursorHorizontal" and "CursorVertical".

    We'll then need to rely on a custom script to:

    • Show the cursor when an item is selected, in the correct position
    • Also switch to "Mouse Over" Hotspot detection at this time
    • Vice-versa when an item is selected

    This can be done using custom events. The script below should do this - copy/paste it into a C# file named DynamicInventoryCursor.cs, and attach to a GameObject in your scene:

    using UnityEngine;
    using AC;
    
    public class DynamicInventoryCursor : MonoBehaviour
    {
    
        private void OnEnable ()
        {
            EventManager.OnInventorySelect_Alt += OnInventorySelect;
            EventManager.OnInventoryDeselect += OnInventoryDeselect;
        }
    
        private void OnDisable ()
        {
            EventManager.OnInventorySelect_Alt -= OnInventorySelect;
            EventManager.OnInventoryDeselect -= OnInventoryDeselect;
            KickStarter.settingsManager.hotspotDetection = HotspotDetection.PlayerVicinity;
        }
    
        private void OnInventorySelect (InvCollection invCollection, InvInstance invInstance)
        {
            Menu inventoryMenu = PlayerMenus.GetMenuWithName ("Inventory");
            MenuInventoryBox inventoryBox = inventoryMenu.GetElementWithName ("InventoryBox") as MenuInventoryBox;
    
            int slot = inventoryBox.GetItemSlot (invInstance);
            if (slot >= 0)
            {
                Vector2 position = inventoryMenu.GetSlotCentre (inventoryBox, slot);
                position.y = ACScreen.height - position.y;
                KickStarter.playerInput.SetSimulatedCursorPosition (position);
            }
    
            KickStarter.playerInput.SetInGameCursorState (false);
            KickStarter.playerInput.CanKeyboardControlMenusDuringGameplay = false;
            KickStarter.settingsManager.hotspotDetection = HotspotDetection.MouseOver;
        }
    
        private void OnInventoryDeselect (InvItem invItem)
        {
            KickStarter.playerInput.SetInGameCursorState (true);
            if (PlayerMenus.GetMenuWithName ("Inventory").IsOn ()) KickStarter.playerInput.CanKeyboardControlMenusDuringGameplay = true;
            KickStarter.settingsManager.hotspotDetection = HotspotDetection.PlayerVicinity;
        }
    
    }
    

    This should give you the ability to select items, move them with the cursor, and use them on Hotspots. Is that the case?

  • edited May 2023

    Amazing, Chris! I can't thank you enough. This is almost perfect.

    Just 2 little hitches left if you have a bit more time

    1) The name of the hotspots displays in at the hidden cursor location in the middle of the screen instead of on the hotspot
    Current behavior
    Desired behavior

    2) Would love it if the inventory could close after a successful drag and drop use. If that's too tough to detect maybe on any drop from a drag-n-drop interaction
    Desired behavior for inventory closing automatically

    Again, thanks a million. This should get me well on my way

  • The name of the hotspots displays in at the hidden cursor location in the middle of the screen instead of on the hotspot

    This is controlled by your Hotspot menu's Position type property, in the Menu Manager. By default, this is set to Follow Cursor (which will cause it to be centered if the cursor is locked). Setting this to On Hotspot will cause it to appear over the currently-selected Hotspot.

    Would love it if the inventory could close after a successful drag and drop use.

    The OnHotspotInteract event can be used to handle this. With this event, you can determine if a given Hotspot interaction was due to Inventory usage, and turn the Inventory menu off if so:

    using UnityEngine;
    using AC;
    
    public class DynamicInventoryCursor : MonoBehaviour
    {
    
        private void OnEnable ()
        {
            EventManager.OnInventorySelect_Alt += OnInventorySelect;
            EventManager.OnInventoryDeselect += OnInventoryDeselect;
            EventManager.OnHotspotInteract += OnHotspotInteract;
        }
    
        private void OnDisable ()
        {
            EventManager.OnInventorySelect_Alt -= OnInventorySelect;
            EventManager.OnInventoryDeselect -= OnInventoryDeselect;
            EventManager.OnHotspotInteract -= OnHotspotInteract;
            KickStarter.settingsManager.hotspotDetection = HotspotDetection.PlayerVicinity;
        }
    
        private void OnInventorySelect (InvCollection invCollection, InvInstance invInstance)
        {
            Menu inventoryMenu = PlayerMenus.GetMenuWithName ("Inventory");
            MenuInventoryBox inventoryBox = inventoryMenu.GetElementWithName ("InventoryBox") as MenuInventoryBox;
    
            int slot = inventoryBox.GetItemSlot (invInstance);
            if (slot >= 0)
            {
                Vector2 position = inventoryMenu.GetSlotCentre (inventoryBox, slot);
                position.y = ACScreen.height - position.y;
                KickStarter.playerInput.SetSimulatedCursorPosition (position);
            }
    
            KickStarter.playerInput.SetInGameCursorState (false);
            KickStarter.playerInput.CanKeyboardControlMenusDuringGameplay = false;
            KickStarter.settingsManager.hotspotDetection = HotspotDetection.MouseOver;
        }
    
        private void OnInventoryDeselect (InvItem invItem)
        {
            KickStarter.playerInput.SetInGameCursorState (true);
            if (PlayerMenus.GetMenuWithName ("Inventory").IsOn ()) KickStarter.playerInput.CanKeyboardControlMenusDuringGameplay = true;
            KickStarter.settingsManager.hotspotDetection = HotspotDetection.PlayerVicinity;
        }
    
        private void OnHotspotInteract (Hotspot hotspot, AC.Button button)
        {
            if (hotspot.GetButtonInteractionType (button) == HotspotInteractionType.Inventory ||
                hotspot.GetButtonInteractionType (button) == HotspotInteractionType.UnhandledInventory)
            {
                PlayerMenus.GetMenuWithName ("Inventory").TurnOff ();
            }
        }
    
    }
    
  • edited May 2023

    That worked like a charm. Thanks a lot Chris
    I think I'm starting to understand how things work.

    If I may make a suggestion, it would be really useful to have some of these behaviors configurable through the New Game Wizard or some preconfigured examples based on more popular games styles.

    The system looks incredibly powerful and extensible. However it's a bit tricky to figure out which collection of options to change to get a specific result.

    Again, really appreciate your help.

  • Noted, thanks for the feedback.

    Something that does go some way towards this are the Downloads and Wiki pages, which both include templates/scripts to achieve specific interaction types.

  • Hi Chris,

    I'm looking to add some side-scrolling portions to the game for action/stealth sequences. I saw there's an engine/input action but was wondering if there's anything more specific.

    In my case I'm looking to disable depth movement (front - backward axis) when the player goes through a trigger and re-enable them at a later point though another trigger.

    Thanks a lot for your time

  • The Engine: Manage systems Action can be used to disable AC's Movement system altogether, but the Player: Constrain Action can be used to limit the Player's movement in a given direction.

    Alternatively, you can set the Player's Motion control field to Manual - either in the Inspector or at runtime through script - to bypass AC's control over the Player completely with a custom script.

  • Amazing, thanks Chris

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.