Multiplayer with AI intergration with PUN AddOn

Zain

New member
I am currently using multiplayer add on of Opsive in Unity and The AI Enemy is designed with the help of behaviour and My problem is The Enemy is not sync with the multiplayer... I mean When masterclient(Photon) instantiate the Enemy AI Character.. It do not perform the same functionality in master and client module.. The Animation which is being performed by the Enemy AI is sync but position is not syncing and also due to this position issue if anyone hit the AI it doesn't take damage. And other hit then it'll take damage... I want the AI to look and work same in every connecting player.
 
To start with the basics - have you gotten player versus player working? There shouldn't be anything different from PUN's standpoint from a character versus AI. Did you use the Character Manager to setup an AI character? To start debugging you should place a log statement within PunCharacterTransformMonitor.OnPhotonSerializeView to see why the position/rotation isn't being synced.
 
Hello

Having the same issue:

1) Character vs character working no problem
2) AI character setup via character manager and its a AI agent
3) AI character setup via PUN manager done as well.
4) BD make single patrol task and enabled only on Master client.

Result:
When AI dies animation is synced and it respawn both, on master and regular client.
However it moves only on Master client.
 
I need to take a closer look at an integration with BD and PUN but for now it does sound like you are approaching it correctly. Have you placed a debug statement within PunCharacterTransformMonitor to see why the location isn't updating?
 
Within PunCharacterTransformMonitor.OnPhotonSerializeView your AI agent should be sending/receiving transform data every fixed update.
 
Here what i got:
I putted debug log under:


C#:
public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
        {
            if (stream.IsWriting) {
                byte dirtyFlag = 0;
                if (m_SynchronizeScale && m_Transform.localScale != m_NetworkScale) {
                    dirtyFlag |= (byte)TransformDirtyFlags.Scale;
                }

                Debug.Log("IsWriting:" + m_PhotonView);

I see that on master client AI Agent sending its position, however on other client it does not receiving it (or i debug wrong).

Another thing that i see, its difference in PhotonView between real player instance and AI Agent.
AI agent have Owner and Creator -> null.

I think problem not in BD, i just instansiate it wrong.
What i made:
1) Put Character on Scene
2) Setup via Opsive Character setup as Ai navMech agent
3) Setup via Pun Addon

Please check the screens:
 

Attachments

  • 2020-11-29_20h47_01.png
    2020-11-29_20h47_01.png
    76.8 KB · Views: 20
  • 2020-11-29_20h47_15.png
    2020-11-29_20h47_15.png
    75.6 KB · Views: 20
Last edited:
On other hand Turret script from Demo scene have same PhotonView settings. But its rotate and get current sync over network.
I am confused.
 
The remote client does not write so it makes sense that you don't see the log. If you place a similar statement for the reading section do you get a callback?

Just as a test you can also use the Pun Transform View instead of the Pun Transform Monitor to see if your AI then syncs.
 
hello I am having the same issue
- Character vs character working fine
- Enemy AI position showing different for master and normal client

Ai is created from Pun Adon and uses navmesh movement ability for movement with the help of a external script
AI is spawned also with a external script by just using PhotonNetwork.Instantiate/InstantiateRoomObject
Single character spawner was not able to spawn AI as it was missing Input component
 
It's tough to for me to say without stepping through it but I'll include a simple AI agent as an example in one of the next updates.
 
It's tough to for me to say without stepping through it but I'll include a simple AI agent as an example in one of the next updates.
Hey Justin, do you have an update on this problem? I have tried using the Photon Transform View in place of the PunTransformMonitor as you outlined earlier. This didn't do anything, the bots are still not being properly synced with the clients. I have also tried adding a PunLocationMonitor, but that also doesn't solve the problem. Also, in my case, I did ensure that the Behavior Tree was not being executed by the clients, so the Behavior Tree isn't interfering with anything either :unsure:
 
Hello, Any progress in this thread. I am having same issue??
The issues with syncing agents was fixed in version 1.2 of the PUN add-on. As for behaviour tree, all you need to do is disable the component for all clients (except the host). If the host changes, then you can re-enable the behaviour tree components inside the OnMasterClientSwitched event, and disable for everybody else.
 
Top