Good news! To provide faster support and grow the community, we'll be changing the forum to "Read Only" and turn to Discord instead for support.
Join here: https://discord.gg/zjNj5zZ

Adding TriggerRangeHandler on Trigger - No UI Displayed

JeffG
Posts: 4
Joined: Tue Jul 11, 2017 6:23 pm

Adding TriggerRangeHandler on Trigger - No UI Displayed

Postby JeffG » Tue Jul 11, 2017 6:27 pm

In the controller Support Demo


Adding a TriggerRangeHandler to a Chest to override the Range. (I used 2) The UI Prompt no longer appears.

JeffG
Posts: 4
Joined: Tue Jul 11, 2017 6:23 pm

Re: Adding TriggerRangeHandler on Trigger - No UI Displayed

Postby JeffG » Tue Aug 15, 2017 2:47 am

Turns out the issue is in PlayerTriggerHandlerBase

If the rangehandler is not null (ie you define one for the item) the

triggersInRange.Add( currentTrigger ) is not called and the UI and input are ignored

Changed code to the following

Note: I did this for controller support. Didn't test for mouse/keyboard. (It might not be necessary)


Code: Select all

  protected void NotifyTriggerEnter(T other)
        {
            var c = other.GetComponentInChildren<TriggerBase>();
            if (c != null && (c.rangeHandler == null || c.rangeHandler.Equals(null)))
            {
                //triggersInRange.Add(c);
                c.NotifyCameInRange(player);
            }


            if (c != null)
                triggersInRange.Add(c);

        }

        protected void NotifyTriggerExit(T other)
        {
            var c = other.GetComponentInChildren<TriggerBase>();
            if (c != null && (c.rangeHandler == null || c.rangeHandler.Equals(null)))
            {
                c.NotifyWentOutOfRange(player);
                triggersInRange.Remove(c);
            }

            if (c != null)
                triggersInRange.Remove(c);

        }

Adressa
Posts: 9
Joined: Wed Aug 30, 2017 6:55 pm

Re: Adding TriggerRangeHandler on Trigger - No UI Displayed

Postby Adressa » Mon Sep 04, 2017 5:38 pm

Hi Jeff, you linked me this thread in my post about triggers, this solution worked for you? I have a loot with a TriggerRangeHandler different to the GeneralSettings and it doesn't work, I changed the script to match the solution you gave but still doesn't work.
Did you do something else?

JeffG
Posts: 4
Joined: Tue Jul 11, 2017 6:23 pm

Re: Adding TriggerRangeHandler on Trigger - No UI Displayed

Postby JeffG » Thu Sep 07, 2017 7:40 pm

I ended up doing something a little bit different

First I added 2 methods to the IPlayerTriggerHandler interface

Code: Select all

public interface IPlayerTriggerHandler
    {
        BestTriggerSelectorBase selector { get; set; }

        TriggerBase selectedTrigger { get; }
        event Action<TriggerBase, TriggerBase> OnSelectedTriggerChanged;

        bool IsInRangeOfTrigger(TriggerBase trigger);
     void AddTriggerInRange(TriggerBase trigger);
        void RemoveTriggerInRange(TriggerBase trigger);
    }


Next....I implemented those methods in the PlayerTriggerHandlerBase

Code: Select all

 public virtual void AddTriggerInRange(TriggerBase trig)
        {
            triggersInRange.Add(trig);
        }
        public virtual void RemoveTriggerInRange(TriggerBase trig)
        {
            triggersInRange.Remove(trig);
        }


I then changed the TriggerRangeHandler (OnTriggerEnter and OnTriggerExit) to call those methods

Code: Select all

 protected void OnTriggerEnter(Collider other)
        {
            var player = other.gameObject.GetComponent<Player>();
            if (player != null)
            {
                _playersInRange.Add(player);
                _trigger.NotifyCameInRange(player);

             
                    // Need to find the PlayerTriggerHandler.  and add this trigger
                    // to the trigger in range var

                    // triggersInRange.Add(c);
                    player.triggerHandler.AddTriggerInRange(_trigger);

             

            }
        }

        protected void OnTriggerExit(Collider other)
        {
            var player = other.gameObject.GetComponent<Player>();
            if (player != null)
            {
                _trigger.NotifyWentOutOfRange(player);
             
                    // Need to find the PlayerTriggerHandler.  and remove this trigger
                    // to the trigger in range var

                    // triggersInRange.Remove(c);
                    player.triggerHandler.RemoveTriggerInRange(_trigger);

             
                _playersInRange.Remove(player);

            }
        }



That fixed my problem.


Return to “Programming”

Who is online

Users browsing this forum: Google [Bot] and 1 guest