Forum rules - please read before posting.

Globally disable Hotspots

edited March 2020 in Technical Q&A

Hello, i need to disable all hotspots in a scene while subtitles are going, because i don't want to lock player during subtitles due to a strange effect it gives when stopped while moving (its a UFPS v2 Player), and because i'm using 16:9 letterbox to show on hotspot name and subtitles, any idea? Actually if i still move while subtitles are on i can see through subtitles the name of the hotspot. I know via disable AC can manage this but subtitles will stop to work as well. Any help :D Thank you

PS
Wrong category, sorry

Comments

  • You can use the Engine: Manage systems Action to disable the Interaction system, which will prevent Hotspots from being interactive.

    If you just want to stop Hotspot names from showing up, you can use the Menu: Change state Action to lock the Hotspot menu.

  • Thank you, it helped :D

  • edited November 2021

    A further question regarding disabling and enabling hotspots. In a PNC adventure game, I have a big room with tens of hotspots. I'd like to be able to disable all of them but one and later enable them back on. Through Engine>Manage systems, disabling the Interaction system would disable all hotspots.

    Is there a way to do this without adding tens of "disable hotspot" and then "enable hotspot" actions?

  • You can do this through scripting. The following script will turn off all Hotspots in the scene, except the one assigned in its component Inspector:

    using UnityEngine;
    using AC;
    
    public class TurnOffHotspots : MonoBehaviour
    {
    
        public Hotspot hotspotToIgnore;
    
        public void TurnOff ()
        {
            foreach (Hotspot hotspot in KickStarter.stateHandler.Hotspots)
            {
                if (hotspot == hotspotToIgnore) continue;
                hotspot.TurnOff ();
            }
        }
    
        public void TurnOn ()
        {
            foreach (Hotspot hotspot in KickStarter.stateHandler.Hotspots)
            {
                if (hotspot == hotspotToIgnore) continue;
                hotspot.TurnOn ();
            }
        }
    }
    

    To use it, paste in a C# file name TurnOffHotspots and add to an empty in the scene. Assign the Hotspot to ignore in its Inspector, and then pass the TurnOn/TurnOff commands to it using the Object: Send message Action.

  • Thanks once again @ChrisIceBox, the script works great. However, there are two things I didn't take into account:

    1. What if I need to have TWO (or more) hotspots ignored by the TurnOff command? Can the empty contain a list of ignored hotspots instead of just one? Preferably with an unrestricted number of entries, to cover possible future uses...

    And the second, more complex issue:

    1. In the room, there are objects that can be picked up. After the player picks them up, their hotspots are disabled. The TurnOn command revives these hotspots as well. Is there a possibility to factor these exceptions in the script? They can't be simply added to the list of ignored hotspots (issue 1), because if they HAVEN'T been picked up YET, they should turn off with the TurnOff command just like the rest.
  • Good points.

    This one allows for multiple Hotspots to be assigned:

    using UnityEngine;
    using AC;
    using System.Collections.Generic;
    
    public class TurnOffHotspots : MonoBehaviour
    {
    
        public List<Hotspot> hotspotsToIgnore = new List<Hotspot> ();
    
        public void TurnOff ()
        {
            foreach (Hotspot hotspot in KickStarter.stateHandler.Hotspots)
            {
                if (hotspotsToIgnore.Contains (hotspot)) continue;
                hotspot.TurnOff ();
            }
        }
    
        public void TurnOn ()
        {
            foreach (Hotspot hotspot in KickStarter.stateHandler.Hotspots)
            {
                if (hotspotsToIgnore.Contains (hotspot)) continue;
                hotspot.TurnOn ();
            }
        }
    }
    

    For the ignoring of Hotspots that are already off: that could be added as well, but you may have issues when it comes to game-saving if you save or load the game after calling TurnOff and before calling TurnOn again.

    In this case, you can either teleport your Hotspots off-screen when you want to disable them completely, or use an alternative script that makes Hotspots non-interactive by assigning an unused camera into each Hotspot's "Limit to Camera" field - though this'll only work if you aren't currently using that feature:

    using UnityEngine;
    using AC;
    using System.Collections.Generic;
    
    public class TurnOffHotspots : MonoBehaviour
    {
    
        public List<Hotspot> hotspotsToIgnore = new List<Hotspot> ();
        public _Camera unusedCamera;
        private List<Hotspot> dynamicHotspotsToIgnore = new List<Hotspot> ();
    
        public void TurnOff ()
        {
            dynamicHotspotsToIgnore.Clear ();
    
            foreach (Hotspot hotspot in KickStarter.stateHandler.Hotspots)
            {
                if (hotspotsToIgnore.Contains (hotspot)) continue;
    
                if (!hotspot.IsOn ())
                {
                    dynamicHotspotsToIgnore.Add (hotspot);
                    continue;
                }
    
                hotspot.limitToCamera = unusedCamera;
            }
        }
    
        public void TurnOn ()
        {
            foreach (Hotspot hotspot in KickStarter.stateHandler.Hotspots)
            {
                if (hotspotsToIgnore.Contains (hotspot)) continue;
                if (dynamicHotspotsToIgnore.Contains (hotspot)) continue;
                hotspot.limitToCamera = null;
            }
    
            dynamicHotspotsToIgnore.Clear ();
        }
    }
    
  • Thank you so much @ChrisIceBox, this works wonders! And a good point regarding potential issues with game-saving. I think the simple teleporting of such hotspots offscreen might be the way to go for me, unless there's a good reason why the latter script should be the preferred solution...

  • Both are valid, it's more down to which workflow you want to use.

  • Hi, I tried the first script as I feel it might become handy for what I'm trying to do, but Unity is throwing this error:
    TurnOffHotspots.cs' must derive from AC's Action class in order to be available as an Action.

  • It looks like you're placing this in an Actions folder - either AC's own or a custom pointed to by the Actions Manager.

    The TurnOffHotspots script isn't an Action - place it in a regular script folder and it should work.

  • I understand now! By the way, is there any package of actions available for AC? It would be great to have a comprehensive package containing the most useful actions that people, or even yourself Chris, have contributed over the years and have them all in one place. It's just an idea that I thought would be helpful. :)

  • That's really the intent behind the AC wiki - though it mainly contains scripts, it can also contain links to .unitypackage files.

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.