How to propery use Player and NPC in Photon multiplayer game

The whole answer can be found below.

Please note: The Photon forum is closed permanently. After many dedicated years of service we have made the decision to retire our forum and switch to read-only: we've saved the best to last! And we offer you support through these channels:

Try Our
Documentation

Please check if you can find an answer in our extensive documentation on PUN.

Join Us
on Discord

Meet and talk to our staff and the entire Photon-Community via Discord.

Read More on
Stack Overflow

Find more information on Stack Overflow (for Circle members only).

Write Us
an E-Mail

Feel free to send your question directly to our developers.

How to propery use Player and NPC in Photon multiplayer game

siten0308
2021-10-20 03:16:32

Hey Everyone,

sorry for the trail off, but just sorta new and being my first multiplayer game, I wanted to try and do this right the first time... I know there will be lessons learned, but if I can learn now, from others mistakes/experiences, then why not...

this is a Unity Photon setup I am doing...

So my game will have at most 5 players with total of 3-5 NPC's at most...

its a mobile game and not sure, but I assume that I need to create 1 prefab for the 5 players, and 3-5 prefabs for each of the NPC's correct in the resource folder for them to sync of to all players?

any other info/tips or maybe even links to multiplayer tutorials will help

thanks in advance.

Comments

[Deleted User]
2021-10-20 03:27:01

How you choose to design your system will depend on your game. Some games don't even use prefab instantiation. But those are games which don't require the player to have a PhotonView.

That being said, each player usually has a prefab instantiated for them. This does not mean you need to make a whole new prefab for each potential player, games usually go the route of just making one prefab, perhaps called "Player" and then instantiating one of those for each player. Remember that you can always configure any properties of the prefab after instantiation through RPCs. So if there is not a big difference between each prefab, you could just have a single prefab and then fill in values after instantiation.

If your NPCs are relatively complex and each require their own prefab, then you can make a separate prefab for each NPC if you really need it.

siten0308
2021-10-20 03:35:28

Hey MeetPun, thanks for your comment,

Yes the players, I was thinking of making or having a prefab, and with the custom properties of each player, will define the look of the player (example, some of the key value is "Player Shirt color" 1 = value, so 1 is blue 2 is red etc. etc.).

thanks for that info, so I will most likely then create a prefab, for each player when they get in the game, thank you on that :)

but the biggest thing I am asking, for the NPC's, most likely there will be just 2-3 NPC's, should I also make a prefab for them? and they will ONLY come out when a certain criteria is met, example, if a certain measure, reaches from 0 to 100, 100 will trigger the NPC to go out and look for the players, should I create an NPC since that would affect all players? or will that not be necessary? or you think I can get away with not creating a prefab, but will it show up for all players on the screen? also want the measure bar whatever to have all players contribute, whether its 5,10,15 etc. until it reaches 100, will that you think require a RPC?

[Deleted User]
2021-10-20 03:42:32

If you want it to sync properly, it's best to make it a prefab and just instantiate it. That way the transform position and rotation will be accurate for all players. It really depends on what the NPC is designed to do and how much movement you intend it to have though. If the NPC doesn't move at all and only spawns itself at a specific place in the world, then you may not need a prefab then.

As for the contribution, you will have to network that data somehow. You could use the room custom properties, events or RPCs. Storing it in the room properties will make it easily available to even newcomers. If someone joins the game at a later stage and you're not using room properties, it will require you to send an RPC to them to "inform" them of the current contribution.

Back to top