Networked AI Agents

nathanj

Active member
Hi Justin

#1 Is there anything I need to do to get Behaviour Tree agents working in a multiplayer scene? We're using the UCC + Pun add on.

None of my behaviour trees get beyond the first node, there is a green line connecting to the first sequencer node but it never passes beyond that.

If we've used the Pun add on to convert our NPCs to Pun do we need to set the variables in behaviour designer to Network Sync?

Somewhat related, I can go an attack and kill an NPC. They will die and respawn but none of their animations are working. The just stand and withstand hits until the ragdol is enabled and they fall. So there is some functionality working, just not the animations and navmesh movement - as far as I can tell.

#2 Also, though relating specifically to UCC, with my interactions I get these errors:

EDIT: I migt have partially solved this by adding the PunInteractableMonitor to the game object that was causing the error so now I don't get the errors but nothing happens when I interact with the NPC - trying to trigger a conversation with Dialogue System.

Code:
Error: The object Bennelong must have a NetworkInteractable component.
UnityEngine.Debug:LogError(Object)
Opsive.UltimateCharacterController.Traits.Interactable:Interact(GameObject) (at Assets/Opsive/UltimateCharacterController/Scripts/Traits/Interactable.cs:91)
Opsive.UltimateCharacterController.Character.Abilities.Interact:DoInteract() (at Assets/Opsive/UltimateCharacterController/Scripts/Character/Abilities/Interact.cs:240)
Opsive.UltimateCharacterController.Game.ScheduledEvent:Invoke() (at Assets/Opsive/UltimateCharacterController/Scripts/Game/Scheduler.cs:80)
Opsive.UltimateCharacterController.Game.Scheduler:Invoke(ScheduledEventBase, Int32) (at Assets/Opsive/UltimateCharacterController/Scripts/Game/Scheduler.cs:661)
Opsive.UltimateCharacterController.Game.Scheduler:FixedUpdate() (at Assets/Opsive/UltimateCharacterController/Scripts/Game/Scheduler.cs:329)
CODE: SELECT ALL

Code:
NullReferenceException: Object reference not set to an instance of an object
Opsive.UltimateCharacterController.Traits.Interactable.Interact (UnityEngine.GameObject character) (at Assets/Opsive/UltimateCharacterController/Scripts/Traits/Interactable.cs:94)
Opsive.UltimateCharacterController.Character.Abilities.Interact.DoInteract () (at Assets/Opsive/UltimateCharacterController/Scripts/Character/Abilities/Interact.cs:240)
Opsive.UltimateCharacterController.Game.ScheduledEvent.Invoke () (at Assets/Opsive/UltimateCharacterController/Scripts/Game/Scheduler.cs:80)
Opsive.UltimateCharacterController.Game.Scheduler.Invoke (Opsive.UltimateCharacterController.Game.ScheduledEventBase scheduledEvent, System.Int32 index) (at Assets/Opsive/UltimateCharacterController/Scripts/Game/Scheduler.cs:661)
Opsive.UltimateCharacterController.Game.Scheduler.FixedUpdate () (at Assets/Opsive/UltimateCharacterController/Scripts/Game/Scheduler.cs:329)

For these do I need to make a custom interactable component?

Thank you,
Nathan
 
Last edited:
I haven't tried a PUN scene with BD but this thread should give you an overview:


For these do I need to make a custom interactable component?
No, you need to attach the PunInteractableMonitor component. You could start by testing the door from the PUN demo scene.
 
Thanks for that link, don’t know how I didn’t see that when i was searching before. Maybe I need to improve my searching skills...

Out of curiosity, have you considered adding a Pun add on for v2 of BD? Might be a nice tie over for UCC.

Nathan
 
Version 2 will allow you to save/load the behavior tree, so it certainly makes it more possible. I do hope to eventually have a PUN integration.
 
Hey @Justin

EDIT: So I just tried converting the Demo scene to Pun and the AI Agent works. Please ignore this,I'll post back if I figure out wat's going on in my scene.

Edit 2: Yup, this is entirely my fault. I'm embarresed to say what happened, but let's just say that if you use Master Scheduler to improve the efficiency of updates make sure it's enabled ?

I'm sorry


I was speaking with Matt on Discord and he suggested I raise my issue with you because he thinks that it is a high priotirty bug because it's preventing any development of Behaviour Desiner with the UCC + Pun integration.

In my scene non of my NPCs or animals work that are UCC Ai Agents and behaviour Designer.

I have an identical scene that hasn't been converted to Pun and everything works exactly as expected. The NPCs follow the navmesh and the Behavoour Trees progress.

However, when I convert the scene and the objects the Behaviour Tress get stuck at the very first node. Doesn't matter wat the node is.

WanderPNG.PNG Repeater.PNG

And the NPCs animator doesn't move beyond the default animation on each layer.

WIth the current capabilities of Behaviour Designer, should the NPCs be able to function within a Pun enviornment in any form? I checked our your link above and I believe that they should, and the syncing is what should will be a challenge.

Sorry to keep on about this,
Nathan
 
Last edited:
I'm sorry, Justin, but this isn't completely resolved.

All of my NPCs are working with Behaviour Designer, UCC (as AI Agents) and Pun.

I have a generic (not humanoid) character that works in the scene if I don't convert it using the Pun wizard but if I do convert it I get this error:

Code:
NullReferenceException: Object reference not set to an instance of an object
Opsive.UltimateCharacterController.Character.AnimatorMonitor.get_ParameterSlotCount () (at Assets/Opsive/UltimateCharacterController/Scripts/Character/AnimatorMonitor.cs:103)
Opsive.UltimateCharacterController.AddOns.Multiplayer.PhotonPun.Character.PunAnimatorMonitor.OnPlayerEnteredRoom (Photon.Realtime.Player player, UnityEngine.GameObject character) (at Assets/Opsive/UltimateCharacterController/Add-Ons/Multiplayer/PhotonPUN/Scripts/Character/PunAnimatorMonitor.cs:90)
Opsive.UltimateCharacterController.Events.InvokableAction`2[T1,T2].Invoke (T1 arg1, T2 arg2) (at Assets/Opsive/UltimateCharacterController/Scripts/Events/InvokableAction.cs:132)
Opsive.UltimateCharacterController.Events.EventHandler.ExecuteEvent[T1,T2] (System.String eventName, T1 arg1, T2 arg2) (at Assets/Opsive/UltimateCharacterController/Scripts/Events/EventHandler.cs:405)
Opsive.UltimateCharacterController.AddOns.Multiplayer.PhotonPun.Game.SpawnManagerBase.SpawnPlayer (Photon.Realtime.Player newPlayer) (at Assets/Opsive/UltimateCharacterController/Add-Ons/Multiplayer/PhotonPUN/Scripts/Game/SpawnManagerBase.cs:205)
Opsive.UltimateCharacterController.AddOns.Multiplayer.PhotonPun.Game.SpawnManagerBase.Start () (at Assets/Opsive/UltimateCharacterController/Add-Ons/Multiplayer/PhotonPUN/Scripts/Game/SpawnManagerBase.cs:126)

I get the error in runtime. If I build the project the first player (master) loads fine but none of the regular players load and the camera just falls on start.

It is possible that I did not set up the animal correctly (a kangaroo) but it works completely fine in the regular build so I don't think that that is the issue.

Sorry to keep up with these vague issues.

Nathan
 
Does AnimatorMonitor.InitializeItemParameters get called before that object is spawned? Within this method the m_ItemSlotID array should be initialized.
 
Ok, figured it out. It's pretty obvious now but I'm still a little confused by it.

My animal npc (kangaroo) that was causing the issue because they didn't have an Inventory and/or Item Set Manager component(s) added to them - just left them blank. This is only an issue when the item is converted to be Pun compatible. The kangaroo did not cause this issue if they were in the scene without the Pun components.

So just to summarise this.

All human NPCs worked fine when being converted and in the build I could load countless clients into a room.

When I added my kangaroo without Pun components into the Pun scene every thing works as expected.

However, when I added my kangaroo with Pun components the first (master) client loads find but throws this error:

Code:
NullReferenceException: Object reference not set to an instance of an object
Opsive.UltimateCharacterController.Character.AnimatorMonitor.get_ParameterSlotCount () (at Assets/Opsive/UltimateCharacterController/Scripts/Character/AnimatorMonitor.cs:103)
Opsive.UltimateCharacterController.AddOns.Multiplayer.PhotonPun.Character.PunAnimatorMonitor.OnPlayerEnteredRoom (Photon.Realtime.Player player, UnityEngine.GameObject character) (at Assets/Opsive/UltimateCharacterController/Add-Ons/Multiplayer/PhotonPUN/Scripts/Character/PunAnimatorMonitor.cs:90)
Opsive.UltimateCharacterController.Events.InvokableAction`2[T1,T2].Invoke (T1 arg1, T2 arg2) (at Assets/Opsive/UltimateCharacterController/Scripts/Events/InvokableAction.cs:132)
Opsive.UltimateCharacterController.Events.EventHandler.ExecuteEvent[T1,T2] (System.String eventName, T1 arg1, T2 arg2) (at Assets/Opsive/UltimateCharacterController/Scripts/Events/EventHandler.cs:405)
Opsive.UltimateCharacterController.AddOns.Multiplayer.PhotonPun.Game.SpawnManagerBase.SpawnPlayer (Photon.Realtime.Player newPlayer) (at Assets/Opsive/UltimateCharacterController/Add-Ons/Multiplayer/PhotonPUN/Scripts/Game/SpawnManagerBase.cs:205)
Opsive.UltimateCharacterController.AddOns.Multiplayer.PhotonPun.Game.SpawnManagerBase.Start () (at Assets/Opsive/UltimateCharacterController/Add-Ons/Multiplayer/PhotonPUN/Scripts/Game/SpawnManagerBase.cs:126)

If I load subsequent clients into the room in build the player's fail to initialise and the camera falls.

To fix this, I added an Inventory and Item Set Manager to the Kangaroo and everything works perfectly.

Nathan
 
Ah, I see what happened. The PUN Add-on is assuming that you are using items with your character.

You can fix this by replacing the loop with:

Code:
            if (HasItemParameters) {
                for (int i = 0; i < ParameterSlotCount; ++i) {
                    m_PhotonView.RPC("SynchronizeItemParametersRPC", player, i, ItemSlotID[i], ItemSlotStateIndex[i], ItemSlotSubstateIndex[i]);
                }
            }

It will also be included in the next update.
 
I just checked and that code is in the released version, PunAnimatorMonitor.OnPlayerEnteredRoom.
 
Hi Justin,

I'm still having the issue that if animal AI do not have an inventory that non master clients are not iniated.

(apologies I haven't responded to the spawning far from 0,0,0 post yet, been trying to get a demo finsihed for this week. Once that's done I'll post a response).

Thanks,
Nathan
 
Top