Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by ehnaton · Sep 01, 2012 at 03:46 PM · multiplayer

Nicknames in multiplayer

I've some problems with nicknames creating in multiplayer.

Can anybody give me a clue how do i have to do it?

Comment
Add comment · Show 5
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ehnaton · Sep 01, 2012 at 04:05 PM 0
Share

sorry, short for nickname.

avatar image landon912 · Sep 01, 2012 at 04:10 PM 0
Share

Do you mean your trying to make different users or accounts and display there usernames?

avatar image ehnaton · Sep 01, 2012 at 04:20 PM 0
Share

only to display their usernames. Nothing more.

avatar image Kiloblargh · Sep 01, 2012 at 05:37 PM 0
Share

Post the relevant portion of your script. It's impossible to tell what you're doing wrong from the amount of information that you gave.

avatar image dscroggi · Sep 28, 2012 at 05:59 AM 0
Share

Basically you'd need to share the name with other players using RPCs like Bunny83 said. To learn how to use Unity built in networking, I suggest you check out the Unity Networking Zero to Hero Guide here:

http://forum.unity3d.com/threads/29015-Uni$$anonymous$$nowledge-entry-Unity-Networking-the-Zero-to-Hero-guide

If you want to make a custom server for use with Unity, check out the video series here:

http://www.youtube.com/watch?v=Clm3yEg1rrI

1 Reply

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by Bunny83 · Sep 27, 2012 at 07:17 PM

Basically it's done like this:

  • When a client joins or changes it's nickname he has to send it via RPC to all other players.

  • The server (which is also a player) stores the names for each player.

  • When new client connects, the server sends a nickname update only to this new player for every other player the server has on his list.

Now it depends on where you store the nicknames. When each player has a player object, it's probably the easiest to store it in a variable of a script on that object.

That's how a player script could look like. Each player object needs of course a NetworkView and in this case it's owned by the respective player.

 //C#
 using UnityEngine;
 
 public class PlayerObject : MonoBehaviour
 {
     private string m_NickName = "";

     void Start()
     {
         // maybe reload the last used name from PlayerPrefs or generate a random name
         BroadcastNickName();
     }

     public void BroadcastNickName()
     {
         networkView.RPC("UpdateNickName", RPCMode.All, m_NickName);
     }

     public void SendNickNameTo(NetworkPlayer aPlayer)
     {
         networkView.RPC("UpdateNickName", aPlayer, m_NickName);
     }

     public void ChangeNick(string aNewNickName)
     {
         if (!networkView.isMine)
             return; // We can only change the nick when we are the owner of this player object
         m_NickName = aNewNickName;
         BroadcastNickName();
     }

     [RPC]
     void UpdateNickName(string aNewNickName)
     {
         if (networkView.isMine)
             return; // We don't want others to change our nickname
         m_NickName = aNewNickName;
     }
 }

On the server you would have a manager class which holds a list of all connected players and their player objects:

 //C#
 using UnityEngine;
 using System.Collections.Generic;
 
 public class Manager : MonoBehaviour
 {
     private List<PlayerObject> m_Players = new List<PlayerObject>();
     void OnPlayerConnected(NetworkPlayer aPlayer)
     {
         foreach(PlayerObject P in m_Players)
             P.SendNickNameTo(aPlayer);
     }
 }

Of course the Manager has to keep his m_Player list up to date, so when a player object is created he has to add it to the list and when he leaves he has to remove it.

When ever a client wants to change his nick, just use ChangeNick();

It depends on how and where the Player objects are created. Maybe you have to do the SendNickNameTo calls a bit later when the new client is ready to receive all nicknames.

Comment
Add comment · Show 5 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Fattie · Sep 27, 2012 at 07:34 PM 0
Share

may have misunderstood...

"When a client joins or changes it's nickname he has to send it* via RPC to all other players. The server (which is also a player) stores the names for each player."

Surely, when a client joins, that new client sends a nickname etc. to the server only. The server then sends it to everyone.

avatar image Bunny83 · Sep 28, 2012 at 03:37 AM 0
Share

Well, of course all communication goes through the server, but RPC$$anonymous$$ode.All effectively sends the RPC to everyone. A client can also send an RPC to another client so it's only executed on this particular client. The RPC passes through the server, but the server doesn't execute the RPC, it just redirects it ;)

avatar image Fattie · Sep 28, 2012 at 07:39 AM 1
Share

"Well, of course all communication goes through the server"

well of course! it's obvious! :)

it's important that the New Networker understands that the server does everything.

I think, a good thought for new networking programmers is that conceptually the clients should be as dumb as possible, and conceptually one should adhere to a hub-and-spoke model as much as possible.

As you say, technically on this system it is possible that ... "A client can also send [a message, effectively directly to] to another client"

Sure, but you can also program with globals and infinite loops!

the hello-Networking-Program$$anonymous$$g formula for "nicknames" is something like

  • for clients...

  • when you connect tell the server your desired nickname

  • have a function "the server has told me my nickname..."

  • have a function "someone else's nickname is..."

  • have a function "someone has left the game..."

  • for servers...

  • have an Array (jk) holding all the nicknames

  • have a function "someone's told me their nickname"

  • have a function "someone's has dropped off or said goodbye"

  • have a function "tell everyone someone's nickname"

  • have a function "tell everyone someone has left"

As a wise man said about $$anonymous$$P networking "at every step you have to engineer as much stupidity as possible into clients"

(Hopefully this benefits Noob Networking Friends.)

Thinking about $$anonymous$$P networking ......... it's very much like remembering ..... being in a war :-O

avatar image Bunny83 · Sep 28, 2012 at 11:37 PM 0
Share

Of course I'm a big friend of authoritative servers, but things like Network.Instantiate works against this concept. So basically Unity's network is designed to be non-authoriataive in the first place. I would say 90% of the people who first head into networking in Unity will do an non-authoriative approach as suggested by most examples in the docs.

The golden rule for the server-client model is usually "never trust a client" but that's not always applicable.

Even a 100% authoriative server (like Quake, my favourite example :D) does not prevent cheating. I would even guess around 20-30% of all players on Quakelive use cheats (wallhack, smooth aimbot, triggerbot, ...). After i found a cheater in my own clan i stopped playing QL.

avatar image Fattie · Sep 29, 2012 at 08:37 AM 0
Share

"but [unity's approach] works against this concept..."

"Unity's network is designed to be non-authoriataive in the first place.."

"say 90% of the people who first head into networking in Unity will do an non-authoriative approach..."

Yeah, I understand exactly what you mean when you explain it that way. O$$anonymous$$.

(Naturally I just ignored / did not really notice :) the non-spoke aspect of Unity, worked around it, and produce normal networking concepts! :) )

Indeed - the same applies with apple's humorous "game kit" system. It leads to the phenomenon where you get kid programmers who think it's normal to converse client-to-client. And then later they are curious about the almost-impossible difficulties that brings.

So, if what you're saying here is 1, 2, 3...

(1) as it happens, Unity's networking presents a very non-spoke face. For that reason,

(2) the fact is every new programmer learning with Unity will whackily grow up using non-spoke networking concepts

(3) it's pointless trying to tell them that this is raving macabre bizarreness, might as well go along

Well fair enough, (2) overrides everything.


Now you mention ..

"Even a 100% authoriative server [ ] does not prevent cheating"

Well that's a bit basically completely wrong dude. You know about online casinos as well as smaller online systems like eg. the world's stock markets, and credit card switches, AT$$anonymous$$ networks, and so on!!! Heh!

Sad to hear quake has gaps in it!

If you're saying (further) that games like quake must logically have some sort of gaps (I can't think off the top of my head how that could possibly be, but if so I believe you) then ok. (Is that what you're saying? It sounds very strange and beyond-Turing you know?!)

{Obviously in for example realtime games there are incidental matters where you don't CARE if the code is gappy. But I can't see any reason that some concept has to be gappy.}


Finally, you say "Network.Instantiate works against [networking]"

I'm not entirely sure that's true. You can set velocity in Unity physics... but that hardly works against using physics. There's jut one line of documentation somewhere that mentions "oh you probably wouldn't normally do this, it's not physical". Similarly you could have a line of docu somewhere that says "oh normally only the 'server' would Instantiate stuff"

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

12 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

A node in a childnode? 1 Answer

Unity and Blender multiplayer chess? 1 Answer

using UnityEditor.EditorUtility.DisplayDialog with ios 0 Answers

Is it possible to do 'click to move' in the free version of Unity 1 Answer

Making an Online Multiplayer Game in Unity's 'Free' Version. 4 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges