• 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 itaielidan · Sep 27 at 10:35 PM · photon

Photon RPC target.All sends info only to the client. * Not Working

Hi everyone, I am trying to create a multiplayer game and am trying to syncronize a manterial through RPCs. now, when I call the function calling the RPC

     public void SyncColor(int c)
     {
         Debug.Log("Sender: " + photonView.ViewID);
         gameObject.GetComponent<PhotonView>().RPC("setColor", RpcTarget.All, c);
     }


everything seems fine. In the unity console during runtime it logs: "Sender: 1001" And when the RPC function gets called:

    [PunRPC]
     public void setColor(int c)
     {
         Debug.Log("Reciever: " + photonView.ViewID);
         GameObject[] blocks = new GameObject[blockParent.transform.childCount];
         for (int i = 0; i< blockParent.transform.childCount; i++)
         blocks[i] = blockParent.transform.GetChild(i).gameObject;
         Debug.Log("Blocks length: " + blocks.Length);
         for(int i = 0; i<blocks.Length; i++)
             blocks[i].GetComponent<Renderer>().material = blocks[i].GetComponent<block>().materials[c];
         Debug.Log("Recieved stone");
     }


In the first row it should log twice as there are 2 players in the current game. it should log: "Reciever: 1001" "Reciever: 2001" And instead of this it only logs "Reciever: 1001" I don't know why this is happening. can anybody help?

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 Captain_Pineapple · Sep 28 at 07:47 AM 0
Share

Hey there,

depends. Where do you actually call the sync color? do you have 2 player objects? if yes then calling sync color should not produce 2 outputs in one instance for only calling synccolor once.


Let me know how often you call this and where then i can elaborate this further.

avatar image itaielidan Captain_Pineapple · Sep 28 at 07:52 AM 0
Share

I am calling the SyncColor method from another gameobject. I am only calling the function once. How do I make this work? I am very new to networking. Thank you

1 Reply

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

Answer by Captain_Pineapple · Sep 28 at 08:32 AM

Hey there,

you somewhat have a false understanding of how this is supposed to work so lets try to clear things up.


Setup:

We have 2 Player, each running their own program instance. Each Player (lets call them A and B) both instantiated a playerobject that they own, so when you call photonView.isMine it should say true.


Now when you call an rpc on A's player with RpcTarget.All this will go to all other program instances the copies of A's player object and trigger the given function there. But since you as the caller of an rpc are also included in RpcTarget.All, the rpc will also bounce back to you. But the only thing that you as player A will see in your program instance and debug log is that you sent 1 message and received 1 message. Player B on the other hand should have a Debuglog telling him that 1 message for the copy of A's player object was received.


So from what you are telling me at this moment everything should be working fine as far as the logs are concerned.


Let me know if something was unclear and if you need further help on this.

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 itaielidan · Sep 28 at 09:54 AM 0
Share

Thank you, really helped

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

117 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

Related Questions

communication ovedr http 0 Answers

photon marco polo tutorial issue with "peercreated" 2 Answers

Photon username script 0 Answers

Rigidbody lag in Photon Cloud Networking. 1 Answer

How to create multyplayer npc? Tips? 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges