Forum rules - please read before posting.

Understand if hotspot is in use via scripting

Hello, i'm trying to activate a postprocess effect only when "use" interaction is used in a hotspot, i've already looked inside the scripting guide in search of something like "use interaction is used" or something similar, but i have serious problems to find what i'm looking for, i know its just my lack on scripting. Any help would be appreciate. Many thanks

Comments

  • You can incorporate whatever change you need into the Hotspot's Interaction ActionList - either by using a custom Action, or with the Object: Call event / Object: Send message Actions to trigger a function in a custom script.

    It's also possible to hook into the OnHotspotInteract custom event, which gets fired when a Hotspot interaction is run. The following script, DetectHotspotInteraction.cs, will detect when the Hotspot it's attached to is interacted with:

    using UnityEngine;
    using AC;
    
    public class DetectHotspotInteraction : MonoBehaviour
    {
    
        private void OnEnable () { EventManager.OnHotspotInteract += OnHotspotInteract; }
    
        private void OnDisable () { EventManager.OnHotspotInteract -= OnHotspotInteract; }
    
        private void OnHotspotInteract (Hotspot hotspot, AC.Button button)
        {
            if (hotspot == GetComponent <Hotspot>())
            {
                // Hotspot was interacted with
            }
        }
    
    }
    
  • Perfect Chris, i've used the script because i'm missing still some knowledge on Object: Call event / Object: Send message. Ive finished the script would you mind to give it a look? Just to tell me if i'm right with the inverse of
    if (hotspot == GetComponent ())

    https://pastebin.com/VQyAa8Gd

    Is that way working with every interactions present in a hotspot or its usable only in a single interaction?

  • Is that way working with every interactions present in a hotspot or its usable only in a single interaction?

    The event will trigger for all interactions, though you can read the properties of the Button parameter if you want to filter them.

    If this effect is intended for all Hotspots - not just specific ones - only one instance of the script is necessary, with no need for a GetComponent check.

    Is that last code block intended to run once the interaction's over? The hotspot parameter will never be null, but you can hook into the OnEnterGameState event to check if the game has re-entered Normal gameplay (assuming the Interaction itself blocks gameplay when running):

    private void OnEnable()
    {
        EventManager.OnHotspotInteract += OnHotspotInteract;
        EventManager.OnEnterGameState += EnterGameState;
    }
    
    private void OnDisable()
    {
        EventManager.OnHotspotInteract -= OnHotspotInteract;
        EventManager.OnEnterGameState -= EnterGameState;
    }
    
    private void OnHotspotInteract(Hotspot hotspot, AC.Button button)
    {
        if (hotspot == GetComponent<Hotspot>() && effectActive == false)
        {
            effectActive = true;
            volume.profile.TryGetSettings(out m_dof);
            m_dof.focusDistance.value = 1.63f;
            m_dof.aperture.value = 15f;
            m_dof.focalLength.value = 92f;
        }
    }
    
    private void EnterGameState (GameState _gameState)
    {
        if (_gameState == GameState.Normal && effectActive == true)
        {
            effectActive = false;
            volume.profile.TryGetSettings(out m_dof);
            m_dof.focusDistance.value = 2.2f;
            m_dof.aperture.value = 27.4f;
            m_dof.focalLength.value = 92f;
        }
    }
    
  • All right, clear. That must work, thanks again, Chris.

  • Ok i'm back on this, i did some try but it didn't work, effect activate when hotspot is on but doesn't turn off, even without giving me some errors or alerts. As i can't still fly by myself, i'm thinking for something maybe more easy to learn based on my scripting skills. Is possible to detect a menu open/close instead of "OnHotspotInteraction"? Probably will help me more. :(

  • edited May 2020

    Well, i'm starting to understand, EventManager is life saver. One last thing on this topic, i did this script, would you mind to give it a check just to tell me if theres something useless or i can avoid to use? Heres the final script ( don't worry about DoF values changing even if effect is off, i just need those as a reminder) XD

    using UnityEngine;
    using AC;
    using UnityEngine.Rendering.PostProcessing;

    public class DetectExamineMenuOpen : MonoBehaviour
    {

    [SerializeField] private PostProcessVolume volume;
    [SerializeField] private PostProcessProfile profile;
    private DepthOfField m_dof;
    public bool effectActive;
    
    private void Start()
    {
    
        volume.profile.TryGetSettings(out m_dof);
        m_dof.active = false;
        m_dof.focusDistance.value = 2.2f;
        m_dof.aperture.value = 27.4f;
        m_dof.focalLength.value = 92f;
    
    
    }
    private void OnEnable()
    {
        EventManager.OnMenuTurnOn += OnMenuTurnOn;
        EventManager.OnMenuTurnOff += OnMenuTurnOff;
    
    
    }
    
    private void OnDisable()
    {
        EventManager.OnMenuTurnOn -= OnMenuTurnOn;
        EventManager.OnMenuTurnOff -= OnMenuTurnOff;
    
    
    
    
    }
    
    private void OnMenuTurnOn(Menu _menu, bool IsInstant)
    {
    
            if (_menu.title == "ExamineMenu" && m_dof.active == false && effectActive == false)
    
        {
                effectActive = true;
                m_dof.active = true;
                volume.profile.TryGetSettings(out m_dof);
                m_dof.focusDistance.value = 1.63f;
                m_dof.aperture.value = 15f;
                m_dof.focalLength.value = 92f;
            }
    
        }
    private void OnMenuTurnOff(Menu _menu, bool IsInstant)
    
    {
        if (_menu.title == "ExamineMenu" && m_dof.active == true && effectActive == true)
        {
            effectActive = false;
            m_dof.active = false;
            volume.profile.TryGetSettings(out m_dof);
            m_dof.focusDistance.value = 2.2f;
            m_dof.aperture.value = 27.4f;
            m_dof.focalLength.value = 92f;
        }
    }
    

    }

  • Looks good to me!

    Only thing I'd suggest is that maybe you can lose the "effectActive" variable, since the m_dof.active is always set to the same value.

  • Thank you 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.