Agents sometimes freeze and do nothing when being spawned

Hello,

I'm using Deathmatch AI with PUN for my bots. The game has 2 teams. If I choose a certain team, then I get assigned the leader of that team when playing offline. I'm using the TeamManager to do so. However, I am noticing that occasionally, only some of the bots will follow me, while others just stand there. Strangely, if I shoot the ones standing there, they sort of 'wake up' and immediately start following me. This happens on and off. If I'm lucky, all of the bots will follow me when they spawn, or all of them will just stand their frozen, until I manually 'wake them up' by shooting at them. I did some observations, and noticed that the bots that are frozen have either: a) have no leader assigned and are trying to seek to a target, when the other bots are following the player, b) get stuck in the V-formation task, or c) stuck in the Wait task at the very beginning, and shooting at them doesn't do anything.

There is also an error associated with the Search For Target task, which happens for those bots who get assigned as leaders, when the player is supposed to be the leader:

Code:
NullReferenceException: Object reference not set to an instance of an object
Opsive.DeathmatchAIKit.AI.Actions.SearchForTarget.NextWaypoint () (at Assets/Plugins/Opsive/DeathmatchAIKit/Scripts/AI/Actions/Attack/SearchForTarget.cs:121)
Opsive.DeathmatchAIKit.AI.Actions.SearchForTarget.OnUpdate () (at Assets/Plugins/Opsive/DeathmatchAIKit/Scripts/AI/Actions/Attack/SearchForTarget.cs:98)
BehaviorDesigner.Runtime.BehaviorManager.RunTask (BehaviorDesigner.Runtime.BehaviorManager+BehaviorTree behaviorTree, System.Int32 taskIndex, System.Int32 stackIndex, BehaviorDesigner.Runtime.Tasks.TaskStatus previousStatus) (at <3ed82e893f584901a16bc2e097c74b57>:0)
BehaviorDesigner.Runtime.BehaviorManager.Tick (BehaviorDesigner.Runtime.BehaviorManager+BehaviorTree behaviorTree) (at <3ed82e893f584901a16bc2e097c74b57>:0)
BehaviorDesigner.Runtime.BehaviorManager.Tick () (at <3ed82e893f584901a16bc2e097c74b57>:0)
BehaviorDesigner.Runtime.BehaviorManager.Update () (at <3ed82e893f584901a16bc2e097c74b57>:0)

I'm assuming the above error is associated with the fact that I haven't set up any waypoints for the bots, so there's no waypoint to seek to. Is there something I'm not doing correctly here? It would be annoying for the player to have to shoot at his teammates just to get them to follow. I am testing with PUN's offline mode, and have followed the tutorial on how to set up the agents. When the bots are working, they will follow the player and engage in combat when necessary, so the behaviour tree does work. It's just this random problem that happens on and off.

Any help would be greatly appreciated, Deathmatch AI is still quite new to me, so there's still a bit of adapting to get used to. Thank you in advance (y)

Image1.JPG

Image2.JPG
 
Last edited:
Since PUN isn't officially supported it's really hard to debug, but that exception does indicate that the waypoints haven't been set. The VFormation task is what the agents use to follow the player. Search For Target will have the agents move on their own.
 
Since PUN isn't officially supported it's really hard to debug, but that exception does indicate that the waypoints haven't been set. The VFormation task is what the agents use to follow the player. Search For Target will have the agents move on their own.
Thanks for the reply Justin. Do you think it's worth trying to get the bots to wait for a longer period of time before they start executing the main behaviour tree (such as increasing the maximum time to 2 or 3 seconds for example, as opposed to the default 0.5)? As far as PUN goes, I'm simply enabling the behaviour tree only for the master client, and the behaviour tree is set to start when the component is enabled. The problem seems to be when they first spawn in, some of them don't get assigned a leader, or some of them get stuck on one of the tasks mentioned above, but if these problems don't happen, then everything works as expected, so it's really the process of getting them spawned and ready to go. I am following on from other posts with regards to spawning in the bots over the network:

C#:
NetworkObjectPool.NetworkSpawn(_botPrefab, ObjectPoolBase.Instantiate(_botPrefab, Vector3.zero, Quaternion.identity), true);

And this is how I enable or disable the behaviour tree component:

C#:
GetComponent<BehaviorTree>().enabled = PhotonNetwork.IsMasterClient;

I understand that Deathmatch AI doesn't officially support PUN (I did dig around for an integration package, but couldn't find one :ROFLMAO:), but I was wondering if you have any general advice or tips on how to get them to work together, at least from the point of view of a generic Behaviour Designer agent? Thanks again for your time.
 
At a high level the behavior tree should run on the master client and then just the transforms are synced. So it sounds like you are approaching it correctly. Unless all of the data hasn't loaded I don't think waiting a longer duration before starting the behavior tree would do anything. It's likely a condition failing within the behavior tree simply because that data hasn't been initialized properly.

Probably the best course of action would be the look at the behavior tree and see what task isn't running or is failing when the game first loads that you'd expect it to run. From there you should have a better idea of the cause and be able to fix it.

Good luck!
 
At a high level the behavior tree should run on the master client and then just the transforms are synced. So it sounds like you are approaching it correctly. Unless all of the data hasn't loaded I don't think waiting a longer duration before starting the behavior tree would do anything. It's likely a condition failing within the behavior tree simply because that data hasn't been initialized properly.

Probably the best course of action would be the look at the behavior tree and see what task isn't running or is failing when the game first loads that you'd expect it to run. From there you should have a better idea of the cause and be able to fix it.

Good luck!
Ok Justin, thanks for the advice. I'll give this a shot and investigate this further, and I'll let you know how I go :D
 
Hey Justin, so I fixed the first problem with the bots not being assigned a leader. This is actually happening by design, there is a 20% chance that a bot will assign himself as a leader, I reduced this to 0% and now all of the bots are being assigned the player as their leader. I do, however, have a more general problem with syncing these bots with clients in a multiplayer scenario, but I wrote about this here:


I have also disabled the DeathmatchAI component during the Awake call, which subsequently prevents the Behavior Tree from being enabled. Only the master client has both of these components enabled. But as I mentioned earlier, there seems to be more of a general issue with the PUN add-on that is preventing the bots from syncing with the clients. Any further clarification would be appreciated. Thanks again.
 
Top