Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 phineliner · Nov 23, 2015 at 05:04 PM · networkingunity5rpclobbyidentifier

UNET - Why is my NetworkInstanceID equal on both clients when receiving ClientRpc?

Hi!

I'm currently playing around with a simple chat system for my gamelobby.

My Setup:

I'm using HLAPI like so:

     //this is called on client within my LobbyPlayer class which inherits from LobbyNetworkPlayer
     public void SendMessage(string msg){
         CmdSendChatMessage(msg, netId.Value);
     }

     //this should be triggered by the client, but executed by the server
     [Command]
     public void CmdSendChatMessage(string message, uint senderID)
     {
         Debug.Log("client "+senderID+" sent a message");
     }

     //this should be triggered by the server but executed by the client
     [ClientRpc]
     public void RpcReceiveChatMessage(string message, uint senderID)
     {
         Debug.Log("client "+netId.Value+" received message from:"+senderID);
     }

As you can see, I send the netId.Value of the respective sending player along with the message. I need this to determine which client sent the message, when another (or same) client receives it.

The problem:

My problem is best explained by an example: If client A triggers sending a message, the Server forwards the Message to client A and B, which is fine. However, both clients seem to have the same netId.Value upon receiving the message:

 //Output when client A sends a message: 
 [Server]: Client 1 sent a message
 [A]: Client 1 received message from: 1  //this is expected
 [B]: Client 1 received message from: 1  //this should be "Client 2 received message from: 1"

The same thing happens when client B triggers sending a message, but then the netId is 2 (on both clients). So it seems, both LobbyPlayers have different netIds, but when they receive the message from the server, their netId is the id of the sender.

The Question:

Why is that? Shouldn't it be like I expected? Or is there a better way to determine which player sent the message?

Cheers, phineliner

Comment
Add comment
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

1 Reply

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

Answer by phineliner · Nov 23, 2015 at 05:44 PM

Alright,

there is no problem with the code, but there was a problem with my understanding of how ClientRpc works. For whatever reason I thought that calling the SendMessage on PlayerObject A would cause the server to call the RpcReceiveChatMessage on PlayerObject B. This, of course, is not the case, so that the Rpc is called on PlayerObject A. And that's why the netId is always the same -> because it is the same object.

To determine which PlayerObject sent the message, you would have to iterate over all player objects of the lobby and compare their netId with the sender id. If you simply would like to check if the message was sent from the local client or a remote client, you could just check for "isLocalPlayer" in the Rpc method.

Hope this helps somebody else.

Cheers phineliner

Comment
Add comment · 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

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

43 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image 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

NetworkManager auto deleting client gameobject when calling it 1 Answer

Unity.Networking (UNet) RPC to Specific Player? Master Server? 4 Answers

On NetworkLobbyManager override, base.OnLobbyServerCreate[Lobby/Game]Player() return null. Is that normal ? 0 Answers

Unet network message or Command/RPC 0 Answers

ClientRPC not getting sent. 0 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