AggroGroup not aggrevating others

OK so at this point in time, I’m sure we’re going in loops. Anyway, here’s the problem:

My AggroGroup straight up isn’t working. In other words, I can attack my Dialogue Guard and activate my aggroGroup as expected, but for god knows what reason, the other guards involved in the group don’t seem to be bothered by the fact that one of their team members is under my attack. I did check their ‘nonAggro’ and ‘aggrevateOthers’ (I set this one to true for my Dialogue Guard, but not the others) setting, and they didn’t work as expected (even though I didn’t change anything about the settings since they were last working, just the game environment in my project had a complete makeover). How do we fix this?

If it helps in anyway, here is my DialogueAggro.cs script:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using RPG.Combat;

namespace RPG.Respawnables
{
    //This class will only go on the character PREFAB that has a dialogue.
    public class DialogueAggro : MonoBehaviour
    {
        //As this is going to be on a prefab, you cannot serialize a scene reference in a prefab...
        //[SerializeField] AggroGroup aggroGroup; 
        AggroGroup aggroGroup;

        //This is the method that your DialogueTrigger will call to Aggrevate. 
        public void CallAggroGroup()
        {
            if (aggroGroup != null) aggroGroup.Activate(true);
        }

        //Sets the aggrogroup, called by RespawnManager so that when the trigger fires, this
        //class has a link to the AggroGroup.
        public void SetAggroGroup(AggroGroup aggroGroup2)
        {
            aggroGroup = aggroGroup2;
        }

    }
}

And my AggroGroup.cs script:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using RPG.Respawnables;
using RPG.Attributes;

namespace RPG.Combat {

    public class AggroGroup : MonoBehaviour
    {

        [SerializeField] List<Fighter> fighters = new List<Fighter>();    // fighters to aggregate when our player takes a wrong dialogue turn (and pisses everyone off)
        [SerializeField] bool activateOnStart = false;
        private bool isActivated;

        private void Start() {

            // Ensures guards are not active to fight you, if you didn't trigger them:
            Activate(activateOnStart);

        }

        /* private void Awake() {

            Health playerHealth = GameObject.FindWithTag("Player").GetComponent<Health>();
            if (playerHealth) playerHealth.onDie.AddListener(() => Activate(activateOnStart));

        } */
        
        /* public void Activate(bool shouldActivate) {

            isActivated = shouldActivate;

            foreach (Fighter fighter in fighters) {

                CombatTarget target = fighter.GetComponent<CombatTarget>();
                
                if (target != null) {

                target.enabled = shouldActivate;

                }

                fighter.enabled = shouldActivate;

            }

        } */

            public void Activate(bool shouldActivate) {

                isActivated = shouldActivate;
                foreach (Fighter fighter in fighters) {

                    if (!fighter) continue;
                    fighter.enabled = shouldActivate;
                    if (fighter.TryGetComponent(out CombatTarget target)) {

                        target.enabled = shouldActivate;

                    }

                }

            }

        /* public void AddFighterToGroup(Fighter fighter) {

            if (fighters.Contains(fighter)) return;
            fighters.Add(fighter);
            if (fighter.TryGetComponent(out CombatTarget target)) {

                target.enabled = isActivated;   // synchronizing fighters with the remainder of the AggroGroup

            }

        } */

        public void AddFighterToGroup(Fighter fighter) {

            if (fighters.Contains(fighter)) return;
            fighters.Add(fighter);
            fighter.enabled = isActivated;
            if (fighter.TryGetComponent(out CombatTarget target)) target.enabled = isActivated;

        }

        public void RemoveFighterFromGroup(Fighter fighter) {

            fighters.Remove(fighter);

        }

    }

}

P.S: (Last time when it used to work, it would work under the condition that I would get close to the group members BEFORE we aggrevate the entire group through dialogue (with the dialogue guard). If you get close to someone you can’t attack, but then aggrevate the group, and the other member you got close to is out of the aggrevated guy’s shout distance, he’d still hunt you down. Now it’s not calling any other member in the group at all, and I’m not sure why…)

For anybody else reading this, this is separate from a normal Aggrogroup situation, dealing with a Respawnable group of characters involved in an Aggrogroup…

Am I understanding that the Aggrogroup WAS working, but now in a new scene, it is not working? Does it still work in the old scene?

This is, I assume, from when it was working…
When you got near the pacified guard, he became a target for fighter… If you’re a target for the fighter, you’re going to stay a target until

  • You’re dead
  • The AI Controller cancels the action

There is no old scene. All I did was hide the old game environment and replace it with something I’d actually consider placing into my game, and for god knows what reason… Although the guys are still assigned to the aggorGroup, they don’t get triggered to fight at all, even if like you said earlier, they become pacifiers that target us unless we are killed or the group is deactivated somehow (I didn’t know there is code that can cancel the AI Code :skull:)

So yes, the guards are still in the aggorGroup, and even though the guard that aggregates everyone else didn’t have a single bit of his settings changed, the guys, even if they are close, just don’t care if he’s under attack or not, even if I get close to them prior to triggering the entire group

I’m trying to get to the bottom of what could have changed… You’re saying the characters were untouched??

Yup, character settings were untouched the last time I checked them

But they were working before?

Did you bake the new scene’s navmesh?

Yes I did bake the new NavMesh

But it -=was=- working before?

yes it was

I think part of the issue is we’ve been doing this over a LOT of threads, necroing other threads, etc… changing the scenery didn’t cause the code to stop working… something had to have changed in the code… I seem to recall a change to the AI Controller in another thread… We’ll have to look into this when I get home from work.

It may just be that respawnables and aggrogroups are too complicated to work together.

yes there was a small change, to allow the patrol guard to stop moving when we engage him in conversation. Here it is, in AIController.Update(), even though commenting it out did not help:

if (isConversant && playerConversant.IsActive() && playerConversant.GetCurrentConversant().gameObject == gameObject) {

            GetComponent<ActionSchedular>().CancelCurrentAction();
            transform.LookAt(player.transform.position);
            return;
        
        }

sure, no worries.

Here’s a quick assignment:
Make an aggrogroup with a speaker that is NOT a respawnable. (i.e. just the characters in the scene, with aggrogroup hooked up correctly, using the normal Aggrogroup.Aggrevate() like Sam does it in the course).
Is that working correctly?

I did the testing, and unfortunately this one is even worse… it doesn’t even deactivate the ‘x’ that locks the second guard out of fighting, so the group is pretty much out the equation now

To be clear, I created a new empty aggrogroup and assigned a dialogue guard and a normal guard under the group. Dialogue guy was acting normally, normal one didn’t

Paste in your Aggrogroup.cs and a screen of the inspector for that and the DialogueTrigger that fires off the Aggrogroup

Sure, here you go:

AggroGroup.cs:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using RPG.Respawnables;
using RPG.Attributes;

namespace RPG.Combat {

    public class AggroGroup : MonoBehaviour
    {

        [SerializeField] List<Fighter> fighters = new List<Fighter>();    // fighters to aggregate when our player takes a wrong dialogue turn (and pisses everyone off)
        [SerializeField] bool activateOnStart = false;
        private bool isActivated;

        private void Start() {

            // Ensures guards are not active to fight you, if you didn't trigger them:
            Activate(activateOnStart);

        }

        /* private void Awake() {

            Health playerHealth = GameObject.FindWithTag("Player").GetComponent<Health>();
            if (playerHealth) playerHealth.onDie.AddListener(() => Activate(activateOnStart));

        } */
        
        /* public void Activate(bool shouldActivate) {

            isActivated = shouldActivate;

            foreach (Fighter fighter in fighters) {

                CombatTarget target = fighter.GetComponent<CombatTarget>();
                
                if (target != null) {

                target.enabled = shouldActivate;

                }

                fighter.enabled = shouldActivate;

            }

        } */

            public void Activate(bool shouldActivate) {

                isActivated = shouldActivate;
                foreach (Fighter fighter in fighters) {

                    if (!fighter) continue;
                    fighter.enabled = shouldActivate;
                    if (fighter.TryGetComponent(out CombatTarget target)) {

                        target.enabled = shouldActivate;

                    }

                }

            }

        /* public void AddFighterToGroup(Fighter fighter) {

            if (fighters.Contains(fighter)) return;
            fighters.Add(fighter);
            if (fighter.TryGetComponent(out CombatTarget target)) {

                target.enabled = isActivated;   // synchronizing fighters with the remainder of the AggroGroup

            }

        } */

        public void AddFighterToGroup(Fighter fighter) {

            if (fighters.Contains(fighter)) return;
            fighters.Add(fighter);
            fighter.enabled = isActivated;
            if (fighter.TryGetComponent(out CombatTarget target)) target.enabled = isActivated;

        }

        public void RemoveFighterFromGroup(Fighter fighter) {

            fighters.Remove(fighter);

        }

    }

}

The screenshot of the inspector, for my AggroGroup of non-respawnable guards:

AggroGroup

DialogueTrigger of my guard that activates the war:

Dialogue Trigger Guard

Since this is a non respawnable, DialogueAggro should not be called. Try removing the entry for DialogueAggro.CallAggroGroup from the trigger.

In the group within a respawn group, remove the AggroGroup.Activate entry in the DialogueTrigger.

none of them got the fix that was required. For the non-respawnable group, DialogueAggro.CallAggroGroup() was deleted off the guard IN THE GAME SCENE, and for the respawnable group, I went and deleted ‘AggroGroup.Activate’ from the PREFAB the aggroGroup was spawning (but left DialogueAggro.CallAggroGroup() there). Still, no fix was properly done for either groups

Once again, I’m baffled…

The code you posted should work flawlessly outside of a Respawnable,

Ok, let’s try to get to the bottom of this:
More Debugs…

        public void Activate(bool shouldActivate)
        {
            Debug.Log($"Aggrogroup {name} Activate({shouldActivate}");
            isActivated = shouldActivate;
            foreach (Fighter fighter in fighters)
            {
                if (!fighter)
                {
                    Debug.Log($"Invalid fighter in configuration");
                    continue;
                }
                Debug.Log($"Setting {fighter}'s status to {shouldActivate}");
                fighter.enabled = shouldActivate;
                if (fighter.TryGetComponent(out CombatTarget target))
                {
                    target.enabled = shouldActivate;
                    Debug.Log($"{fighter}'s Combat target set to {target.enabled}");
                }
                Debug.Log($"{fighter}'s enabled state = {fighter.enabled}");
            }
        }

You should be seeing a set of debugs when they are deactivated at the beginning of the scene, and a set of debugs when they are activated by the dialogue.

Hey Brian. Apologies for the extremely late response (most of my responses from now on will probably be late as well, for external reasons). Here is what the Debug.Log pumps out:

For the non-Respawnable AggroGroup:


And for the Respawnable AggroGroup:


Privacy & Terms