Forum rules - please read before posting.

Cursor not changing for Narrator NPC speaking, but will for Player

edited January 2023 in Technical Q&A

HI Chris, so I have my Cursor parameters all set up and working fine, except when either IsSpeaking, InConversation or InCutscene are True I want the IdleCursor to be active again so the Use, pick up etc all deactivate, currently I am out of ideas?

Here is the code from the script attached to my cursor (as well as Unity UI Cursor script)

using UnityEngine.UI;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using AC;

public class CursorScript : MonoBehaviour
{
    public Animator _animator;
    public string useIconIDParameter = "UseIconID";
    public string hasLookIconParameter = "HasLookIcon";
    public string speechParameter = "IsSpeaking";
    public string conversationParameter = "InConversation";
    public RawImage rawImageToControl;


    private void OnEnable ()
    {
        EventManager.OnStartSpeech_Alt += StartSpeech;
        EventManager.OnStopSpeech_Alt += StopSpeech;
        EventManager.OnStartConversation += StartConversation;
        EventManager.OnEndConversation += EndConversation;
        EventManager.OnClickConversation += ClickConversation;
        EventManager.OnHotspotInteract += OnHotspotInteract;

    }

    private void OnDisable ()
    {
        EventManager.OnStopSpeech_Alt -= StopSpeech;
        EventManager.OnStartSpeech_Alt -= StartSpeech;
        EventManager.OnStartConversation -= StartConversation;
        EventManager.OnEndConversation -= EndConversation;
        EventManager.OnClickConversation -= ClickConversation;
        EventManager.OnHotspotInteract -= OnHotspotInteract;

    }

    private void OnHotspotInteract (Hotspot hotspot, AC.Button button)
    {
        _animator.SetTrigger ("Interaction");
    }


    private void StartSpeech (Speech speech)
    {
        _animator.SetBool (speechParameter, true);
    }

    private void StopSpeech (Speech speech)
    {
        _animator.SetBool (speechParameter, false);
    }

    private void StartConversation (Conversation conversation)
    {
        _animator.SetBool (conversationParameter, true);
    }

    private void EndConversation (Conversation conversation)
    {

    }

    private void ClickConversation (Conversation conversation, int optionId)
    {
        _animator.SetBool (conversationParameter, false);
    }

    private void Update ()
    {
        bool hasLookIcon = false;
        int useIconID = -1;

        if (AC.KickStarter.stateHandler.IsInGameplay ())
        {
            AC.Hotspot hotspot = AC.KickStarter.playerInteraction.GetActiveHotspot ();
            if (hotspot)
            {
                hasLookIcon = hotspot.HasContextLook ();
                if (hotspot.HasContextUse ())
                {
                    useIconID = hotspot.GetFirstUseButton ().iconID;
                }
            }
        }
        int menuOverrideID = KickStarter.playerMenus.GetElementOverCursorID ();
        _animator.SetInteger ("MenuOverrideID", menuOverrideID);
        _animator.SetInteger (useIconIDParameter, useIconID);
        _animator.SetBool (hasLookIconParameter, hasLookIcon);
        int cursorID = KickStarter.playerMenus.GetElementOverCursorID ();
        if (cursorID < 0) cursorID = KickStarter.playerCursor.GetSelectedCursorID ();
        _animator.SetInteger ("CursorID", cursorID);
        _animator.SetInteger ("InvID", (KickStarter.runtimeInventory.SelectedItem != null) ? KickStarter.runtimeInventory.SelectedItem.id : -1);
        _animator.SetBool ("IsInCutscene", KickStarter.stateHandler.IsInCutscene ());


        if (rawImageToControl)
    {
        if (KickStarter.runtimeInventory.SelectedItem != null)
    {
        _animator.enabled = false;
        rawImageToControl.texture = KickStarter.runtimeInventory.SelectedItem.tex;
    }
        else
    {
        _animator.enabled = true;
    }
}


    }
}

Please see video, thanks:

https://drive.google.com/drive/folders/1CHHGGnT93WB4ZJxfnRKyP6dLaaUKmkri?usp=sharing

Comments

  • Your video shows no speech from either the narrator nor the player.

    As you're controlling the cursor's display with animator parameters, what are the parameter values when the issue occurs vs when it works?

  • edited January 2023

    Sorry Chris, I now have adapted the ask but it is relevant to the script above - when I open my inventory and hover over my inventory items, my cursor does not change at all. The parameter for InvID and InventoryID stay at -1 with inventory open and inventory close. See screenshots here, thanks! I need the same options of cursor as a normal hotspot in game, ie if it has use and or examine etc.

    https://drive.google.com/drive/folders/1Qdhw-AiUdsEoFg4tR1PaAoFl9_mp-wPV?usp=share_link

  • edited January 2023

    Or at least to choose what icon i want for hover over inventory icons, ie maybe just the pick up hand animation?

  • The ability to associate a cursor icon with an Inventory Use interaction is only available if your Settings Manager's Inventory interactions field is set to Multiple. Is this the case? If not, how are you looking to associate the two together? Naming convention on the linked ActionList asset could be one option.

  • If it's not showing, it's because it's not available. This'll be the case if you're using Context Sensitive interactions.

  • edited January 2023

    ah yes, i am, can you explain further on the alt option please? What does the InvID and InventoryID from my script do?

  • InventoryID (from Unity UI Cursor) and InvID (from your script) both serve the same purpose. When an item is selected, they'll be set to the ID number of that item - and -1 otherwise. This ID is unrelated to the ID of any Interaction Icon.

    If your intent is to have another parameter that presents an icon ID, which changes when hovering over items, my suggestion was to name each item's "Use" interaction ActionList with a naming convention that can be used to access it. For example:

    Look_Key
    Use_Phone
    Eat_Sandwich

    If these prefixes (before the underscore) matched the icon names defined in the Cursor Manager, they could then be feasibly read by the script and used to set a separate Animator Integer parameter with that icon's ID.

    Does that sound correct?

  • edited January 2023

    Hi Chris, I guess so, although that would be a TON of parameters, would there not be an easier way of simply having HoverInventory parameter coded into the script so that at least the cursor could turn into the Use cursor when hovered over the inventory items?

    Would you be able to show me how I would integrate into my script for both options please? Thanks!

  • Having a parameter change to the ID of the hovered-over item is simple enough. I need you to be clear: are you looking to change to different icons based on the hovered item (and if so, how many?), or is changing to a single "Use" icon enough?

  • Ideally, a use and examine for each inv item, but at the very least just the use

  • Adding this line to your script will set an Animator Integer parameter named "HoverInvID" to the ID of the currently-hovered-over item:

    _animator.SetInteger ("HoverInvID", (KickStarter.runtimeInventory.hoverItem != null) ? KickStarter.runtimeInventory.hoverItem.id : -1);
    
  • Hi Chris do I simply add that line or do i need to add other code?

  • ok so i got this working thanks! But how do I then have no cursor visible once I have selected an item. I currently still have the pickup icon over the inventory object I then select. Whereas before it would just be pointer cursor and this would disappear on selection of inventory object. THanks!

  • When an item is selected, your "InvID" parameter will be larger than -1. Use this to affect what animation is played via Transitions.

  • HI, I'm struggling to get this to work, please would you mind taking a look at my video here. Also, the picked up object does not disappear once it becomes the cursor.

    https://drive.google.com/file/d/1ngSP5elw8ocg5pqdJT_oFtONk1LyQEkt/view?usp=share_link

    Thanks Chris

  • It's all to do with the way your Transitions are configured - both the conditions and where they start from. You can have Transitions be set up according to parameter values, but if the animation state they start from isn't playing, they won't kick in.

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.