Forum rules - please read before posting.

After almost 4 years, new problem without solution! (for me)

Turns out, I checked again this plugin to make a LucasArts's "The Dig" remake, but I got a problem here. Main Cursor doesn't animate when hovering over Inventory icons, and when I add a custom cursor by using the "Change cursor when over?" It starts animating but not only over Inventory items, but over the Inventory spaces too!

Is there any way to make the cursor only animating when hovering over Inventory items without using the "When slot is empty: Disable object" method?

I was thinking on making the Inventory cursor appear when Inventory appears but I wasn't able to do it via ActionScript, and I wasn't able to write my own script to do this, so is there any alternative ways to solve this?

«1

Comments

  • Welcome back, @Kit.

    You can attach a script to your UI Canvas prefab that toggles the Change cursor when over? property at runtime, based on whether or not an Inventory item is currently being hovered over. You'll need to make sure the string fields in its Inspector match the names of your Menu / InventoryBox element, but this should do it:

    using UnityEngine;
    using AC;
    
    public class InvCursor : MonoBehaviour
    {
    
        public string menuName = "Inventory";
        public string inventoryElementName = "Items";
        private MenuInventoryBox inventoryBox;
    
        void Update()
        {
            if (inventoryBox == null) inventoryBox = PlayerMenus.GetElementWithName (menuName, inventoryElementName) as MenuInventoryBox;
    
            bool showCursor = InvInstance.IsValid (KickStarter.runtimeInventory.HoverInstance);
            inventoryBox.changeCursor = showCursor;
        }
    }
    

    Alternatively, if you rely on Unity UI for your Cursor rendering (as set in the Cursor Manager) you can animate the cursor itself using Animator paramaters, setting e.g. a bool to True whenever the cursor is hovering over an item.

  • I was using AC Canvas, am I strictly forced to use an Unity UI Prefab Canvas in order to do what I want?

  • Not at all - if you use AC as the Menu's Source, placing the script in the scene should still work.

  • error CS0103: The name 'InvInstance' does not exist in the current context

    error CS1061: 'RuntimeInventory' does not contain a definition for 'HoverInstance' and no accessible extension method 'HoverInstance' accepting a first argument of type 'RuntimeInventory' could be found (are you missing a using directive or an assembly reference?)

  • What is your current AC version? The script assumes the latest is imported.

  • 1.65.2

  • edited June 2024

    Try replacing:

    bool showCursor = InvInstance.IsValid (KickStarter.runtimeInventory.HoverInstance);
    

    with:

    bool showCursor = KickStarter.runtimeInventory.hoverItem != null;
    
  • KitKit
    edited June 2024

    Thanks, and I got another small issue. I used your script (As seen here: https://adventurecreator.org/forum/discussion/7891/click-and-hold-on-hotspot-to-make-a-verb-coin-appear) and when I hold the mouse button inside my inventory menu, the interactions menu appears with the Inventory item selected. Is there a way to select the item by pressing the mouse button, but showing the Interactions method WITHOUT selecting the item when holding the mouse button?

  • Sorry, I'm not 100% clear on your meaning - is this to say that an item gets selected when clicking in the Menu, before the hold time has completed? I can't reproduce such an issue in the current release.

    Could you share screenshots of your Menu, InventoryBox, and Settings Manager as well?

  • Yes that was I'm trying to mean, I'll try to send all the screenshots

  • https://imgur.com/a/IhlSmK0

    Any chance to edit this code so the menu would trigger only if you're not holding an inventory item?

    using UnityEngine;
    using System.Collections;
    using AC;

    public class VerbCoin : MonoBehaviour
    {

    public float maxHoldTime = 0.5f;
    private float heldTime;
    
    
    private void Update ()
    {
        if (Input.GetMouseButton (0) &&
            (KickStarter.playerInteraction.GetActiveHotspot () != null || KickStarter.runtimeInventory.hoverItem != null) &&
            KickStarter.stateHandler.IsInGameplay () &&
            !KickStarter.playerMenus.IsInteractionMenuOn ())
        {
            // LMB is held down over a Hotspot or inventory item, during gameplay, and when no Interaction menu is showing
    
            heldTime += Time.deltaTime;
            if (heldTime >= maxHoldTime)
            {
                // Open the Interaction menu
                if (KickStarter.runtimeInventory.hoverItem != null)
                {
                    // For an inventory item
                    KickStarter.playerMenus.EnableInteractionMenus (KickStarter.runtimeInventory.hoverItem);
                }
                else
                {
                    // For a Hotspot
                    KickStarter.playerMenus.EnableInteractionMenus (KickStarter.playerInteraction.GetActiveHotspot ());
                }
                heldTime = 0f;
            }
        }
        else if (!Input.GetMouseButton (0) &&
            (KickStarter.playerInteraction.GetActiveHotspot () != null || KickStarter.runtimeInventory.hoverItem != null) &&
            KickStarter.stateHandler.IsInGameplay () &&
            KickStarter.playerMenus.IsInteractionMenuOn ())
        {
            KickStarter.playerMenus.CloseInteractionMenus ();
            heldTime = 0f;
        }
    }
    

    }

  • After:

    // LMB is held down over a Hotspot or inventory item, during gameplay, and when no Interaction menu is showing
    

    You can insert the following to prevent any more code running if an Inventory item is selected:

    if (KickStarter.runtimeInventory.selectedItem != null) return;
    
  • And some ideas about my previous question?

  • Assets\VerbCoin.cs(20,34): error CS0122: 'RuntimeInventory.selectedItem' is inaccessible due to its protection level

  • And some ideas about my previous question?

    I can't reproduce the issue in v1.65.2 either - are you relying on any other custom scripts that may be causing the item to become selected?

    This script, placed in the scene, will display a log in the Console when an item becomes selected. What does it show, in full, when an item becomes selected due to clicking it in the Menu, before the Interaction menu turns on?

    using UnityEngine;
    using AC;
    
    public class LogItemSelection : MonoBehaviour
    {
    
        void OnEnable () { EventManager.OnInventorySelect += OnInventorySelect; }
        void OnDisable () { EventManager.OnInventorySelect -= OnInventorySelect; }
    
        void OnInventorySelect (InvItem invItem)
        {
            Debug.Log ("Selected item " + invItem.label);
        }
    
    }
    

    Assets\VerbCoin.cs(20,34): error CS0122: 'RuntimeInventory.selectedItem' is inaccessible due to its protection level

    Use this:

    if (KickStarter.runtimeInventory.SelectedItem != null) return;
    
  • Yes, it shows. I got an idea, by using the "Prevent Interactions?" method or something related, make something like this

    If heldTime equals or is greater than, let's say, 0.15, the item cannot be selected, otherwise if heldTime is less than 0.15, you can select the item.

  • I need to know what the log shows. Select the message in the Console, and copy/paste it in full - stacktrace included.

  • [20:38:01] Selected item Worm

  • Sorry I misunderstood, this is the full log:

    Selected item Paper code
    0x00007ff638e6c36c (Unity) StackWalker::GetCurrentCallstack
    0x00007ff638e74749 (Unity) StackWalker::ShowCallstack
    0x00007ff63a35d27c (Unity) GetStacktrace
    0x00007ff63b45f9b3 (Unity) DebugStringToFile
    0x00007ff638ec6956 (Unity) DebugLogHandler_CUSTOM_Internal_Log
    0x000001e67a54b6cb (Mono JIT Code) (wrapper managed-to-native) UnityEngine.DebugLogHandler:Internal_Log (UnityEngine.LogType,UnityEngine.LogOption,string,UnityEngine.Object)
    0x000001e67a54b5fb (Mono JIT Code) UnityEngine.DebugLogHandler:LogFormat (UnityEngine.LogType,UnityEngine.Object,string,object[])
    0x000001e67a54b340 (Mono JIT Code) UnityEngine.Logger:Log (UnityEngine.LogType,object)
    0x000001e67a54b208 (Mono JIT Code) UnityEngine.Debug:Log (object)
    0x000001e67a54b1ab (Mono JIT Code) [LogItemSelection.cs:13] LogItemSelection:OnInventorySelect (AC.InvItem)
    0x000001e67a54b110 (Mono JIT Code) [EventManager.cs:834] AC.EventManager:Call_OnChangeInventory (AC.InvItem,AC.InventoryEventType,int)
    0x000001e67a54af5b (Mono JIT Code) [RuntimeInventory.cs:183] AC.RuntimeInventory:SelectItem (AC.InvItem,AC.SelectItemMode)
    0x000001e67a549e73 (Mono JIT Code) [MenuInventoryBox.cs:847] AC.MenuInventoryBox:HandleDefaultClick (AC.MouseState,int,AC.AC_InteractionMethod)
    0x000001e67a5494ab (Mono JIT Code) [RuntimeInventory.cs:1898] AC.RuntimeInventory:ProcessInventoryBoxClick (AC.Menu,AC.MenuInventoryBox,int,AC.MouseState)
    0x000001e67a54906b (Mono JIT Code) [MenuInventoryBox.cs:1583] AC.MenuInventoryBox:ProcessClick (AC.Menu,int,AC.MouseState)
    0x000001e67a53f003 (Mono JIT Code) [PlayerMenus.cs:2287] AC.PlayerMenus:CheckClick (AC.Menu,AC.MenuElement,int,AC.MouseState)
    0x000001e67a5303cb (Mono JIT Code) [PlayerMenus.cs:1933] AC.PlayerMenus:CheckClicks (AC.Menu)
    0x000001e679c17ff3 (Mono JIT Code) [PlayerMenus.cs:2022] AC.PlayerMenus:CheckForInput ()
    0x000001e679c0cc03 (Mono JIT Code) [StateHandler.cs:303] AC.StateHandler:Update ()
    0x000001e679b4c460 (Mono JIT Code) (wrapper runtime-invoke) object:runtime_invoke_void__this__ (object,intptr,intptr,intptr)
    0x00007ffa66cde630 (mono-2.0-bdwgc) [mini-runtime.c:2812] mono_jit_runtime_invoke
    0x00007ffa66c62ac2 (mono-2.0-bdwgc) [object.c:2921] do_runtime_invoke
    0x00007ffa66c6bb1f (mono-2.0-bdwgc) [object.c:2968] mono_runtime_invoke
    0x00007ff638cf47c4 (Unity) scripting_method_invoke
    0x00007ff638ced115 (Unity) ScriptingInvocation::Invoke
    0x00007ff638c9f554 (Unity) MonoBehaviour::CallMethodIfAvailable
    0x00007ff638c9f65c (Unity) MonoBehaviour::CallUpdateMethod
    0x00007ff63816d938 (Unity) BaseBehaviourManager::CommonUpdate
    0x00007ff63817788a (Unity) BehaviourManager::Update
    0x00007ff6385ddcea (Unity) InitPlayerLoopCallbacks'::2'::UpdateScriptRunBehaviourUpdateRegistrator::Forward
    0x00007ff6385bf01c (Unity) ExecutePlayerLoop
    0x00007ff6385bf0f3 (Unity) ExecutePlayerLoop
    0x00007ff6385c5f29 (Unity) PlayerLoop
    0x00007ff6399f6391 (Unity) PlayerLoopController::UpdateScene
    0x00007ff6399f4026 (Unity) Application::TickTimer
    0x00007ff63a366a71 (Unity) MainMessageLoop
    0x00007ff63a36aab1 (Unity) WinMain
    0x00007ff63c1bae86 (Unity) __scrt_common_main_seh
    0x00007ffafb2c7344 (KERNEL32) BaseThreadInitThunk
    0x00007ffafb4626b1 (ntdll) RtlUserThreadStart

  • Oh and two more requests before I stop bothering you lol

    Double clicking to teleport (and disable this option when a boolean variable is false)

    Use "." to skip dialogues

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.