Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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
1
Question by PersianKiller · Apr 20 at 07:35 AM · networking

NetCodeForGameobjects Rpc for a specific client

I'm using netcode for gameobjects for my multiplayer game,I use this code to spawn an object in clients

  [ClientRpc]
 public void test1ClientRpc()
 {

     GameObject ob = Instantiate(Obj,new Vector3(0,0,0),Quaternion.Euler(0,0,0));
 
 }


but the problem is that it sends this code to all clients, I want it to send it for a specific client.

now I'm using this code,

     [ClientRpc]
      public void test1ClientRpc()
 {

     if (NetId==2)
     {
         GameObject ob = Instantiate(Obj, new Vector3(0, 0, 0), Quaternion.Euler(0, 0, 0));

     }

 }

it works fine but it has a problem .server still sends the code to all clients,then they check the condition and .... , I want to send it only for that specific client :)

Comment
Add comment · Show 2
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 andrew-lukasik · Apr 20 at 09:29 AM 0
Share

(My guess is that) RPC can send arguments over the network.

 [ClientRpc]
 public void test1ClientRpc ( int specificNetId )
 {
     if( this.NetId==specificNetId )
     {
         /* code */
     }
 }
avatar image PersianKiller andrew-lukasik · Apr 20 at 12:59 PM 0
Share

yes but as I said in this case server has to send it to all clients.then they have to check the condition :) want to send it for a specific client not all clients :)

1 Reply

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

Answer by andrew-lukasik · Apr 20 at 01:19 PM

https://docs-multiplayer.unity3d.com/netcode/current/advanced-topics/message-system/rpc-params/index.html

 [ClientRpc]
 public void MySpecificClientRpc ( ClientRpcParams clientRpcParams )
 {
     /* code */
 }


Comment
Add comment · Show 1 · 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 PersianKiller · Apr 21 at 02:23 AM 2
Share
 private void DoSomethingServerSide(ulong clientId)
 {
     // If is not the Server/Host then we should early return here!
      if (!IsServer) return;


     // NOTE! In case you know a list of ClientId's ahead of time, that does not need change,
     // Then please consider caching this (as a member variable), to avoid Allocating Memory 
     every time you run this function
    
     ClientRpcParams clientRpcParams = new ClientRpcParams
     {
         Send = new ClientRpcSendParams
         {
             TargetClientIds = new ulong[] { clientId }
         }
     };

     DoSomethingClientRPC(clientRpcParams);

         }


         [ClientRpc]
         private void DoSomethingClientRPC(ClientRpcParams clientRpcParams = default)
         {
     if (IsOwner) return;
      
     // Run your client-side logic here!!
     Debug.LogFormat(" w");


    
   

         }


        private void Update()
         {


            if (Input.GetKeyDown(KeyCode.W))
             {


                 DoSomethingServerSide(3);


             }

           }

so it will send it for the client 3 ,.thanks .

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

188 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 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 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 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 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

Unity networking tutorial? 6 Answers

Unet host only code 1 Answer

RPC and how to talk to clients 0 Answers

What are my options for real-time networking to a backend service in 2017? 0 Answers

Network Tutorial Interpolation - TPS Auth 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