Pun V2 NPCs

Hello all, I spent so far 2 days looking through the forums, looking for youtube videos and other documentation to try and figure out how to spawn and move NPCs over PUN. I would really appreciate some help in this matter, a point in the right direction.

With the basic spawn command, all clients spawn their own NPC. So I restricted spawning to the master client. This would spawn a single npc for all people connected but only allow it to move on the master client, of course. When debugging, I see that the NPC is only spawning correctly for the Master and not other clients. None of its values get set. It literally just spawns the NPC in its spawn location and that's it.

How can i properly spawn a NPC for all clients, set its values and go from there?

Thanks in advance!


  • Hi @Nargdev,

    if you use PhotonNetwork.Instantiate, you have to use a position parameter, at which the object gets created on all clients. To synchronize any changes (e.g. position, rotation, etc.) you have to add either one of the included *View components (e.g. the PhotonTransformView component) or add a custom OnPhotonSerializeView solution to that object. In both cases the also attached PhotonView component has to observe the other component.
  • Thank you. I decided to go another route where the server hands what npcs are spawned and their data then send the command to the clients to spawn them. The issue I am trying to figure out now, is when interacting with the npc, how to tell the other clients whats happening. Like, updating which user is interacting with them and what not.
  • Since this NPC is a networked object, you could for example use RPCs to set a certain variable. Just as a simple example: the NPC has a variable isTalkingTo of type int. By default this value is -1. Whenever a client starts talking to that NPC, the value changes to the ActorNumber of the client who is talking to the NCP. When the client leaves the conversation, this variable is set to -1 again.
  • Thank you for your help. I managed to get them working properly and should be able to move forward with my game on that front.
Sign In or Register to comment.