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 /
  • Help Room /
avatar image
0
Question by CoderNation1 · Mar 14, 2018 at 11:48 PM · networkingphotonrpc

Sending RPC to specific photon players.

Hi, I need help sending an RPC to a specific photon player. I don't want to send it to all players since I'm sending over an int from a master client to another client.

What is the best way to send an RPC to a client that RPC'd the master?

All this code works except for "RPC_SetSpawnIndex()" In RPC_GetNextSpawn() the master would increment their spawnindex and then pass that int back to the client that RPC'd the master client.

So when it comes to the master client sending back a message to the client that RPC'd the master it just doesn't work. Nothing happens. No error or anything...

Here's my code.

 [PunRPC]
     private void RPC_GetNextSpawn(PhotonMessageInfo info) // Gets the spawn point from the master client
     {
         print("Master Received Message from:"+ info.sender);
         spawnPos++;
         PhotonView.RPC("RPC_SetSpawnIndex", info.sender, spawnPos); // Sends master clients spawnindex to sender.
     }
 
     [PunRPC]
     private void RPC_SetSpawnIndex(PhotonMessageInfo info, int pos) // Sender receives the clients index and sets it as their own
     {
         //print("I," + PhotonNetwork.player.NickName + " From " + info.sender);
         //print("I," + PhotonNetwork.player.NickName + " set my spawn to :"+pos+", From"+info.sender);
         spawnPos = pos;
     }
 
     [PunRPC]
     private void RPC_CreatePlayer() // Spawns the player
     {
         GameObject[] spawnPoints = GameObject.FindGameObjectsWithTag("SpawnPoint");
 
         PhotonView.RPC("RPC_GetNextSpawn", PhotonTargets.MasterClient);
 
         print("My name is "+ PhotonNetwork.player.NickName +" My New Spawn Point Index: "+spawnPos);
 
         GameObject tankInstance = PhotonNetwork.Instantiate("Tank_Networked", spawnPoints[spawnPos].transform.position, spawnPoints[spawnPos].transform.rotation, 0);
 
         tankInstance.GetComponent<TankController>().SetColors(); // Sets the color of the tank from the client.
     }

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

3 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by BazilBaachu · Feb 24, 2020 at 05:14 PM

Hey i am new to unity and i too wanted to send rpc to a specific player but i couldn't find a good solution in forums. So after playing with my code for a while i found a solution that helped me to send RPC to a specific player. The PhotonView. RPC method has an overload where Player is the parameter instead of RPCTARGET, through which i could send the rpc to the specific client passing his index in PhotonNetwork.playerlists.

It worked for my situation. Hope it help others too : )

,Hi, I don't know if you got the solution but for me i haven't got what i wanted from any forum :( . But after playing with my code i figured how to send RPC to a specific player. The PhotonView. RPC method has an overload where it takes a Player as a parameter instead of RpcTarget. So that you could send the RPC to a specific person. If you have the index of the player in PhotonNetwork. Playerlists, you could send rpc to that specific player.

Hope it helps... :)

Comment
Add comment · Show 2 · 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 chillysakin · Mar 05, 2020 at 02:15 PM 0
Share

thanks i figured some of it

avatar image octav88 · Mar 30, 2021 at 08:48 AM 0
Share

@BazilBaachu This solution worked for me, thanks a lot :'D

avatar image
0

Answer by ChristianSimon · Mar 15, 2018 at 10:40 AM

Hi,

I don't know if sending a RPC from inside another RPC is a good solution at all. Maybe using RaiseEvent or the Player Custom Properties is a better solution in this case.

When using the RaiseEvent function you have the advantage that you don't need a PhotonView component for communication. You can also set the client, who will receive the message you are going to send next. To see how RaiseEvent works, I would recommend you taking a look at the RPCs and RaiseEvent documentation page.

To tell a client the index of his spawn, you can either use another RaiseEvent call again or use the Player's Custom Properties.

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

Answer by Sanjay112000 · Feb 28, 2021 at 06:01 AM

Thank you bazilbaachu(https://answers.unity.com/users/1127669/bazilbaachu.html).

I am posting my entire workflow of instantiating players at different positions:

Initially checking whether we are master client or not:

Then obtain list of players and send rpc to each of them individually on positions to spawn them.You can store an array of positions and send index in rpc.

Here is the code:

photonView = PhotonView.Get(this); if(PhotonNetwork.IsMasterClient) { foreach(Player pl in PhotonNetwork.PlayerList) { //Debug.Log(pl); photonView.RPC("InstantiationPlayer",pl,index);

             index++;
         }
     }

  [PunRPC]
     void InstantiationPlayer(int index)
     {
         
 

PhotonNetwork.Instantiate(Playerprefabs[value].name,SpawnPoints[index].transform.position, Quaternion.identity, 0); }

Thank you.

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

175 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

Related Questions

Photon RPC 2 Answers

Strange (Pun2) RPC Problem. (With Error message that doesn't appear in a google search at all) 1 Answer

Photon RPC Only Working Halfway 1 Answer

Photon RPC Parameter NullReferenceException 1 Answer

[Photon Networking] Passing My Player scripts 'Target' object to the Uncontrolled version of My Player 1 Answer


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