[UNET] networkmanager numplayers

Updated on July 24, 2018 in [A] Multiplayer
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
3 on June 14, 2018

hi im working on a simple multiplayer game with unet.

and i want to use networkmanager “numplayers” to save it on mysql DB.

but when first player connect to server , numplayers is still zero !

and when scound player connect it going to 1 !

it Always a number less than the true value !

why ?

is this a bug ?!

 

  • Liked by
Reply
2 on June 15, 2018

Because everything starts counting at 0 (with exceptions ofcourse but that will be stated with the function itself), if you didn’t know that already that I think you should start at the beginning of programming in C# or JS instead of starting with UNET 😉

Wise
on June 15, 2018

That’s not 100% correct. The count only starts at 0 when you’re checking the ORDER of something, not its quantity. If there are 2 players in a list, yes player 2 would have an index of 1, but numPlayers would still be 2.

 

Maybe the host is never being added to the list of players and that’s why the count doesn’t increase until a 2nd (non-host) player connects.

 

Helpful
on July 24, 2018

That’s not 100% correct. The count only starts at 0 when you’re checking the ORDER of something, not its quantity. If there are 2 players in a list, yes player 2 would have an index of 1, but numPlayers would still be 2.

 

Maybe the host is never being added to the list of players and that’s why the count doesn’t increase until a 2nd (non-host) player connects.

 

From Mouledoux

 If I check the documentation (https://docs.unity3d.com/ScriptReference/Networking.NetworkManager-numPlayers.html) it states:

“NumPlayers is the number of active player objects across all connections on the server. This is only valid on the host / server.”

So I think this is your problem?

Show more replies
  • Liked by
Reply
Cancel