Forum rules - please read before posting.

Hotspots Flash all clumped together

Hi Chris, after updating to the latest AC, I've noticed that my flash SmallHotspotLabels are now all clumped together rather than placed where the actul hotspot should be. Please see video and screenshots here:

https://www.dropbox.com/scl/fo/gdzhg7naku2zax6tntum0/h?rlkey=muzdtsv8k0xzlrvu93wuy3brb&dl=0

And my flashhotspots code below:

using UnityEngine;
using System.Collections.Generic;
#if UNITY_EDITOR
using UnityEditor;
#endif

namespace AC
{

    [System.Serializable]
    public class ActionFlashHotSpots : Action
    {

        public float flashDuration = 1.5f;
        public string menuName = "SmallHotspotLabels"; // The name of the Hotspot Menu to copy
        public string labelName = "HotspotSmallLabel"; // The Label element of the Hotspot Menu
        private List<Menu> localMenus;

        public override ActionCategory Category { get { return ActionCategory.Custom; }}
        public override string Title { get { return "FlashHotspot"; }}

        public override float Run ()
        {
            if (!isRunning)
            {
                localMenus = new List<Menu> ();

                Hotspot[] hotspots = FindObjectsOfType (typeof (Hotspot)) as Hotspot[];
                foreach (Hotspot hotspot in hotspots)
                {
                  if (hotspot.enabled && hotspot.IsOn () && hotspot.PlayerIsWithinBoundary () && hotspot.highlight && hotspot != KickStarter.playerInteraction.GetActiveHotspot () && (KickStarter.settingsManager.hotspotDetection == HotspotDetection.MouseOver || KickStarter.player.hotspotDetector.IsHotspotInTrigger (hotspot)))



                    {
                        hotspot.Flash ();
                        ShowForHotspot (hotspot);
                    }
                }

                isRunning = true;
                return flashDuration;
            }

            foreach (Menu menu in localMenus)
            {
                menu.TurnOff ();
                KickStarter.playerMenus.UnregisterCustomMenu (menu, false);
            }

            isRunning = false;
            return 0f;
        }

        private void ShowForHotspot (Hotspot hotspot)
        {
            Menu menuToCopy = PlayerMenus.GetMenuWithName (menuName);
            if (menuToCopy == null)
            {
                ACDebug.LogWarning ("Cannot find menu with name '" + menuName + "'", this);
                return;
            }
            Menu myMenu = ScriptableObject.CreateInstance<Menu> ();

            myMenu.CreateDuplicate (menuToCopy); // Copy from the default Menu
            myMenu.appearType = AppearType.Manual; // Set it to Manual so that we can control it easily
            myMenu.isLocked = false; // Unlock it so that the default can remain locked if necessary
            myMenu.title += this.name;
            myMenu.SetHotspot (hotspot, null); // Link it to the Hotspot

            if (!string.IsNullOrEmpty (labelName))
            {
                (myMenu.GetElementWithName (labelName) as MenuLabel).labelType = AC_LabelType.Normal;
                (myMenu.GetElementWithName (labelName) as MenuLabel).label = hotspot.GetName (Options.GetLanguage ());
            }

            myMenu.TurnOn ();

            KickStarter.playerMenus.RegisterCustomMenu (myMenu, true);
            localMenus.Add (myMenu);
        }

        #if UNITY_EDITOR

        public override void ShowGUI ()
        {
            menuName = EditorGUILayout.TextField ("Menu name:", menuName);
            labelName = EditorGUILayout.TextField ("Label name:", labelName);
        }

        #endif

    }

}
«1

Comments

  • What version were you updating from?

  • edited February 2024

    I cannot remember. I only tried the flash hotspots recently, a good while after updating, and they were clumped together. I an on Version 1.79.3, UNity 2021.3.15f1

  • Replace:

    myMenu.SetHotspot (hotspot, null); // Link it to the Hotspot
    

    with:

    myMenu.HotspotLabelData.SetData (hotspot, string.Empty);
    
  • Hi, I have noticed that when I am flashing the hotspots (using tab input) and move the cursor, the words group together. See video:

    https://www.dropbox.com/scl/fi/lmybgl8v68kqrark8m2du/Tab-Grouping-Words.mkv?rlkey=b7xawfnpy05nh3s0n8ppwrmf3&st=lpk4qcgc&dl=0

    Is there anyway to keep them still for the period of flashing please?

  • This thread is a year old, now. I'll need updated information:

    • What is your AC version?
    • Are you using the same script above?
    • Have you made the replacement mentioned above?
    • What are the properties of the Menu involved?
  • Hi,

    AC 180.5

    This is the updated script for keeping hotspots on screen until the input key is depressed:

    using UnityEngine;
    using System.Collections;
    using System.Collections.Generic;
    #if UNITY_EDITOR
    using UnityEditor;
    #endif
    
    namespace AC
    {
        [System.Serializable]
        public class ActionHoldToFlashHotspots : Action
        {
            public string inputName = "FlashHold"; // The input name defined in the Input Manager
            public string menuName = "SmallHotspotLabels"; // The name of the Hotspot Menu to copy
            public string labelName = "HotspotSmallLabel"; // The Label element of the Hotspot Menu
            private List<Menu> localMenus;
            private bool keepFlashing = true;
    
            public override ActionCategory Category { get { return ActionCategory.Custom; }}
            public override string Title { get { return "HoldToFlashHotspot"; }}
    
            public override float Run()
            {
                if (!isRunning)
                {
                    Debug.Log("ActionHoldToFlashHotspots: Starting action");
                    localMenus = new List<Menu>();
    
                    Hotspot[] hotspots = FindObjectsOfType(typeof(Hotspot)) as Hotspot[];
                    foreach (Hotspot hotspot in hotspots)
                    {
                        if (hotspot.enabled && hotspot.IsOn() && hotspot.PlayerIsWithinBoundary() && hotspot.highlight && hotspot != KickStarter.playerInteraction.GetActiveHotspot() && (KickStarter.settingsManager.hotspotDetection == HotspotDetection.MouseOver || KickStarter.player.hotspotDetector.IsHotspotInTrigger(hotspot)))
                        {
                            ShowForHotspot(hotspot);
                        }
                    }
    
                    isRunning = true;
                    keepFlashing = true;
                    CoroutineRunner.Instance.StartCoroutine(FlashHotspotsCoroutine());
                    return defaultPauseTime;
                }
    
                StopFlashing();
                return 0f;
            }
    
            private IEnumerator FlashHotspotsCoroutine()
            {
                Debug.Log("FlashHotspotsCoroutine: Coroutine started");
                while (keepFlashing)
                {
                    if (!KickStarter.playerInput.InputGetButton(inputName))
                    {
                        Debug.Log("FlashHotspotsCoroutine: Input button released, stopping flash");
                        keepFlashing = false;
                    }
                    yield return null;
                }
    
                StopFlashing();
            }
    
            private void StopFlashing()
            {
                Debug.Log("StopFlashing: Stopping all flashes");
                foreach (Menu menu in localMenus)
                {
                    Debug.Log($"StopFlashing: Turning off menu {menu.title}");
                    menu.TurnOff();
                    KickStarter.playerMenus.UnregisterCustomMenu(menu, false);
                }
    
                localMenus.Clear();
                isRunning = false;
            }
    
            private void ShowForHotspot(Hotspot hotspot)
            {
                Menu menuToCopy = PlayerMenus.GetMenuWithName(menuName);
                if (menuToCopy == null)
                {
                    Debug.LogWarning($"ActionHoldToFlashHotspots: Cannot find menu with name '{menuName}'");
                    return;
                }
    
                Menu myMenu = ScriptableObject.CreateInstance<Menu>();
                myMenu.CreateDuplicate(menuToCopy); // Copy from the default Menu
                myMenu.appearType = AppearType.Manual; // Set it to Manual so that we can control it easily
                myMenu.isLocked = false; // Unlock it so that the default can remain locked if necessary
                myMenu.title += this.name;
                myMenu.HotspotLabelData.SetData(hotspot, string.Empty);
    
                if (!string.IsNullOrEmpty(labelName))
                {
                    MenuLabel menuLabel = myMenu.GetElementWithName(labelName) as MenuLabel;
                    if (menuLabel != null)
                    {
                        menuLabel.labelType = AC_LabelType.Normal;
                        menuLabel.label = hotspot.GetName(Options.GetLanguage());
                    }
                    else
                    {
                        Debug.LogWarning($"ActionHoldToFlashHotspots: Cannot find label with name '{labelName}'");
                    }
                }
    
                myMenu.TurnOn();
                Debug.Log($"ShowForHotspot: Turning on menu {myMenu.title} for hotspot {hotspot.name}");
                KickStarter.playerMenus.RegisterCustomMenu(myMenu, true);
                localMenus.Add(myMenu);
            }
    
            #if UNITY_EDITOR
    
            public override void ShowGUI()
            {
                inputName = EditorGUILayout.TextField("Input name:", inputName);
                menuName = EditorGUILayout.TextField("Menu name:", menuName);
                labelName = EditorGUILayout.TextField("Label name:", labelName);
            }
    
            #endif
        }
    }
    

    Menu properties here:

    https://www.dropbox.com/scl/fo/u3uv79sh91p7ayitr9yc3/AEVXzDq6dVgN0nnqFhrWKNg?rlkey=3s2zkbfnidg7pv3apr4924qte&st=qh36avhi&dl=0

    Thanks

  • Underneath:

    myMenu.HotspotLabelData.SetData(hotspot, string.Empty);
    

    Try adding:

    myMenu.HotspotLabelData.UpdateAutoPosition (myMenu);
    myMenu.positionType = PositionType.OnHotspot;
    myMenu.uiPositionType = UIPositionType.OnHotspot;
    
  • edited January 15

    getting this error

    Assets/Sleepytime Village/Scripts/CustomActions/ActionHoldToFlashHotspots.cs(94,26): error CS0103: The name 'PositionType' does not exist in the current context

  • myMenu.HotspotLabelData.UpdateAutoPosition (myMenu);
    myMenu.positionType = AC_PositionType.OnHotspot;
    myMenu.uiPositionType = UIPositionType.OnHotspot;
    
  • Thanks for that, but unfortunately they still clump together

  • So to reiterate, whilst the input key is held down to flash the hotspots (they stay on screen until you release the input key) and if you simultaneously move the cursor, the hotspots all clump together in the same position.

  • Remove the change above, instead set the Menu's Position type to Manual, and add this to the bottom of ShowForHotspot:

    myMenu.HotspotLabelData.UpdateAutoPosition (myMenu);
    

    If your scenes support scrolling, add this to to the while loop of FlashHotspotsCoroutine so that their positions remain updated:

    foreach (var myMenu in localMenus)
    {
        myMenu.HotspotLabelData.UpdateAutoPosition (myMenu);
        myMenu.positionType = AC_PositionType.Manual;
        myMenu.uiPositionType = UIPositionType.Manual;
    }
    
  • Tried this, as below, but still happening:

    using UnityEngine;
    using System.Collections;
    using System.Collections.Generic;
    #if UNITY_EDITOR
    using UnityEditor;
    #endif
    
    namespace AC
    {
        [System.Serializable]
        public class ActionHoldToFlashHotspots : Action
        {
            public string inputName = "FlashHold"; // The input name defined in the Input Manager
            public string menuName = "SmallHotspotLabels"; // The name of the Hotspot Menu to copy
            public string labelName = "HotspotSmallLabel"; // The Label element of the Hotspot Menu
            private List<Menu> localMenus;
            private bool keepFlashing = true;
    
            public override ActionCategory Category { get { return ActionCategory.Custom; }}
            public override string Title { get { return "HoldToFlashHotspot"; }}
    
            public override float Run()
            {
                if (!isRunning)
                {
                    Debug.Log("ActionHoldToFlashHotspots: Starting action");
                    localMenus = new List<Menu>();
    
                    Hotspot[] hotspots = FindObjectsOfType(typeof(Hotspot)) as Hotspot[];
                    foreach (Hotspot hotspot in hotspots)
                    {
                        if (hotspot.enabled && hotspot.IsOn() && hotspot.PlayerIsWithinBoundary() && hotspot.highlight && hotspot != KickStarter.playerInteraction.GetActiveHotspot() && (KickStarter.settingsManager.hotspotDetection == HotspotDetection.MouseOver || KickStarter.player.hotspotDetector.IsHotspotInTrigger(hotspot)))
                        {
                            ShowForHotspot(hotspot);
                        }
                    }
    
                    isRunning = true;
                    keepFlashing = true;
                    CoroutineRunner.Instance.StartCoroutine(FlashHotspotsCoroutine());
                    return defaultPauseTime;
                }
    
                StopFlashing();
                return 0f;
            }
    
            private IEnumerator FlashHotspotsCoroutine()
            {
                Debug.Log("FlashHotspotsCoroutine: Coroutine started");
                while (keepFlashing)
                {
                    foreach (var myMenu in localMenus)
                    {
                        myMenu.HotspotLabelData.UpdateAutoPosition(myMenu);
                        myMenu.positionType = AC_PositionType.Manual;
                        myMenu.uiPositionType = UIPositionType.Manual;
                    }
    
                    if (!KickStarter.playerInput.InputGetButton(inputName))
                    {
                        Debug.Log("FlashHotspotsCoroutine: Input button released, stopping flash");
                        keepFlashing = false;
                    }
                    yield return null;
                }
    
                StopFlashing();
            }
    
            private void StopFlashing()
            {
                Debug.Log("StopFlashing: Stopping all flashes");
                foreach (Menu menu in localMenus)
                {
                    Debug.Log($"StopFlashing: Turning off menu {menu.title}");
                    menu.TurnOff();
                    KickStarter.playerMenus.UnregisterCustomMenu(menu, false);
                }
    
                localMenus.Clear();
                isRunning = false;
            }
    
            private void ShowForHotspot(Hotspot hotspot)
            {
                Menu menuToCopy = PlayerMenus.GetMenuWithName(menuName);
                if (menuToCopy == null)
                {
                    Debug.LogWarning($"ActionHoldToFlashHotspots: Cannot find menu with name '{menuName}'");
                    return;
                }
    
                Menu myMenu = ScriptableObject.CreateInstance<Menu>();
                myMenu.CreateDuplicate(menuToCopy); // Copy from the default Menu
                myMenu.appearType = AppearType.Manual; // Set it to Manual so that we can control it easily
                myMenu.isLocked = false; // Unlock it so that the default can remain locked if necessary
                myMenu.title += this.name;
                myMenu.HotspotLabelData.SetData(hotspot, string.Empty);
    
                if (!string.IsNullOrEmpty(labelName))
                {
                    MenuLabel menuLabel = myMenu.GetElementWithName(labelName) as MenuLabel;
                    if (menuLabel != null)
                    {
                        menuLabel.labelType = AC_LabelType.Normal;
                        menuLabel.label = hotspot.GetName(Options.GetLanguage());
                    }
                    else
                    {
                        Debug.LogWarning($"ActionHoldToFlashHotspots: Cannot find label with name '{labelName}'");
                    }
                }
    
                myMenu.HotspotLabelData.UpdateAutoPosition(myMenu); // Update the menu's position
                myMenu.TurnOn();
                Debug.Log($"ShowForHotspot: Turning on menu {myMenu.title} for hotspot {hotspot.name}");
                KickStarter.playerMenus.RegisterCustomMenu(myMenu, true);
                localMenus.Add(myMenu);
            }
    
            #if UNITY_EDITOR
    
            public override void ShowGUI()
            {
                inputName = EditorGUILayout.TextField("Input name:", inputName);
                menuName = EditorGUILayout.TextField("Menu name:", menuName);
                labelName = EditorGUILayout.TextField("Label name:", labelName);
            }
    
            #endif
        }
    }
    
  • Put:

    myMenu.HotspotLabelData.UpdateAutoPosition (myMenu);
    

    At the very bottom.

  • Hi Chris, the hotspots just appear in the middle of the screen and not over the hotspot if i put Menu's Position type to Manual. And if not then it still doesn't work.

    The full script:

    using UnityEngine;
    using System.Collections;
    using System.Collections.Generic;
    #if UNITY_EDITOR
    using UnityEditor;
    #endif
    
    namespace AC
    {
        [System.Serializable]
        public class ActionHoldToFlashHotspots : Action
        {
            public string inputName = "FlashHold"; // The input name defined in the Input Manager
            public string menuName = "SmallHotspotLabels"; // The name of the Hotspot Menu to copy
            public string labelName = "HotspotSmallLabel"; // The Label element of the Hotspot Menu
            private List<Menu> localMenus;
            private bool keepFlashing = true;
    
            public override ActionCategory Category { get { return ActionCategory.Custom; }}
            public override string Title { get { return "HoldToFlashHotspot"; }}
    
            public override float Run()
            {
                if (!isRunning)
                {
                    Debug.Log("ActionHoldToFlashHotspots: Starting action");
                    localMenus = new List<Menu>();
    
                    Hotspot[] hotspots = FindObjectsOfType(typeof(Hotspot)) as Hotspot[];
                    foreach (Hotspot hotspot in hotspots)
                    {
                        if (hotspot.enabled && hotspot.IsOn() && hotspot.PlayerIsWithinBoundary() && hotspot.highlight && hotspot != KickStarter.playerInteraction.GetActiveHotspot() && (KickStarter.settingsManager.hotspotDetection == HotspotDetection.MouseOver || KickStarter.player.hotspotDetector.IsHotspotInTrigger(hotspot)))
                        {
                            ShowForHotspot(hotspot);
                        }
                    }
    
                    isRunning = true;
                    keepFlashing = true;
                    CoroutineRunner.Instance.StartCoroutine(FlashHotspotsCoroutine());
                    return defaultPauseTime;
                }
    
                StopFlashing();
                return 0f;
            }
    
            private IEnumerator FlashHotspotsCoroutine()
            {
                Debug.Log("FlashHotspotsCoroutine: Coroutine started");
                while (keepFlashing)
                {
                    foreach (var myMenu in localMenus)
                    {
                        myMenu.positionType = AC_PositionType.Manual;
                        myMenu.uiPositionType = UIPositionType.Manual;
                    }
    
                    if (!KickStarter.playerInput.InputGetButton(inputName))
                    {
                        Debug.Log("FlashHotspotsCoroutine: Input button released, stopping flash");
                        keepFlashing = false;
                    }
                    yield return null;
                }
    
                StopFlashing();
            }
    
            private void StopFlashing()
            {
                Debug.Log("StopFlashing: Stopping all flashes");
                foreach (Menu menu in localMenus)
                {
                    Debug.Log($"StopFlashing: Turning off menu {menu.title}");
                    menu.TurnOff();
                    KickStarter.playerMenus.UnregisterCustomMenu(menu, false);
                }
    
                localMenus.Clear();
                isRunning = false;
            }
    
            private void ShowForHotspot(Hotspot hotspot)
            {
                Menu menuToCopy = PlayerMenus.GetMenuWithName(menuName);
                if (menuToCopy == null)
                {
                    Debug.LogWarning($"ActionHoldToFlashHotspots: Cannot find menu with name '{menuName}'");
                    return;
                }
    
                Menu myMenu = ScriptableObject.CreateInstance<Menu>();
                myMenu.CreateDuplicate(menuToCopy); // Copy from the default Menu
                myMenu.appearType = AppearType.Manual; // Set it to Manual so that we can control it easily
                myMenu.isLocked = false; // Unlock it so that the default can remain locked if necessary
                myMenu.title += this.name;
                myMenu.HotspotLabelData.SetData(hotspot, string.Empty);
    
                if (!string.IsNullOrEmpty(labelName))
                {
                    MenuLabel menuLabel = myMenu.GetElementWithName(labelName) as MenuLabel;
                    if (menuLabel != null)
                    {
                        menuLabel.labelType = AC_LabelType.Normal;
                        menuLabel.label = hotspot.GetName(Options.GetLanguage());
                    }
                    else
                    {
                        Debug.LogWarning($"ActionHoldToFlashHotspots: Cannot find label with name '{labelName}'");
                    }
                }
    
                myMenu.TurnOn();
                myMenu.HotspotLabelData.UpdateAutoPosition(myMenu); // Update the menu's position at the very bottom
                Debug.Log($"ShowForHotspot: Turning on menu {myMenu.title} for hotspot {hotspot.name}");
                KickStarter.playerMenus.RegisterCustomMenu(myMenu, true);
                localMenus.Add(myMenu);
            }
    
            #if UNITY_EDITOR
    
            public override void ShowGUI()
            {
                inputName = EditorGUILayout.TextField("Input name:", inputName);
                menuName = EditorGUILayout.TextField("Menu name:", menuName);
                labelName = EditorGUILayout.TextField("Label name:", labelName);
            }
    
            #endif
        }
    }
    

    Screenshot of my menu:

    https://www.dropbox.com/scl/fi/ci1in7ciyklhjt7zho88y/Screenshot-2025-01-19-at-11.34.50.png?rlkey=47rsmmndrfa71flabmbussgzz&st=0gd9947t&dl=0

  • my bad, works a treat!!

  • I've noticed that these do not fade in and out, unlike when I hover in game. Can you help me amend the script so they do? thanks

  • You'll need to register them before turning on, and unregister them only once they're completely faded out.

  • I;m now actually using UnityUI for my hotspots but they do not turn off/fade out when the flashhotsposts input is released, any ideas? (sames menu and element names) thanks

  • Fading in UI requires a Canvas Group component on the root.

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.