The Pause Duration countdown in the Patrol task does not pause.

EVG

Member
I pause the Behavior Tree using behaviorTree.StopBehavior(true); and everything seems fine, but in the Patrol task, the Pause Duration countdown keeps running and does not stop while paused, even though logically it seems like it should.

BD Pro 3.
 
Here’s what Codex helped me implement. I also changed some private variables to protected to allow overrides, and added access to Index since I need it when reducing the number of waypoints to avoid an out-of-range array error.

C#:
        protected int m_Index;
        protected float m_NextDestinationTime;
        protected float m_PatrolPauseStartTime = -1f;
        public int Index { get => m_Index; set => m_Index = value; }

        public override void Pause(World world, Entity entity)
        {
            base.Pause(world, entity);

            // Store the moment when the tree was paused.
            if (m_PatrolPauseStartTime < 0f)
            {
                m_PatrolPauseStartTime = Time.time;
            }
        }

        public override void Resume(World world, Entity entity)
        {
            base.Resume(world, entity);

            if (m_PatrolPauseStartTime < 0f)
            {
                return;
            }

            var pausedDuration = Time.time - m_PatrolPauseStartTime;

            // If it was waiting at a waypoint when paused, shift the wait timer.
            if (m_NextDestinationTime >= 0f)
            {
                m_NextDestinationTime += pausedDuration;
            }

            m_PatrolPauseStartTime = -1f;
        }
Everything seems to be working well, but I’ll still wait for your official fix. :)
 
Last edited:
Back
Top