• 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 carnivoris · Jun 30, 2015 at 02:00 PM · photonrpc

RPC Call for Round Countdown Executes Late on Remote Clients

I'm using an RPC call to initiate the pre-round countdown for my multiplayer game (PUN), but the countdown doesn't begin on the remote clients until it's finished on the master client.

 public void roundCountdown()
     {
         GetComponent<PhotonView>().RPC("roundCountdown_RPC", PhotonTargets.All);
     }
 
     [RPC]
     void roundCountdown_RPC()
     {
         roundStartScreen = GameObject.Find("RoundStartScreen(Clone)");
         roundStartScreen.transform.GetChild(0).GetComponent<Text>().text = "Round Starting In";
 
         
         InvokeRepeating("decreaseTimeRemaining", 1.0f, 1.0f);
 
         if (roundCountdownTimer == 0)
         {
             Debug.Log("roundCountdownTimer = " + roundCountdownTimer);
             startPlayer();
             HUDCanvasGO.transform.FindChild("RoundTimer").GetComponent<RoundTimer>().hasStarted = true;
         }
 
     }

Could someone explain the reason that the countdown executes on the master client (the only client that can start the round without a full room) and THEN the other clients? I thought PhotonTargets.All meant that the target function would be run on all clients at approximately the same time.

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
0

Answer by tobiass · Jul 10, 2015 at 09:20 AM

PhotonTargets.All uses a "shortcut" and executes the RPC instantly on the local client. The others get it a bit later, when the message got through the network.

You can use PhotonTargets.AllViaServer to send the RPC back to the client which called it.

The script InRoomRoundTimer.cs could be interesting to check out, too. It sets a property when the game starts. Based on this, rounds start over and over again, but you can also just use it to initially start your game.

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 carnivoris · Jul 13, 2015 at 01:26 AM 0
Share

AllViaServer sounds like what I need, but nothing seems to happen when I use it. Are there any criteria for what kind of functions can be called via RPC? I'm trying to just call a function that calls StartCoroutine() to start the timer function. Is there another technique I should be using if I want to use AllViaServer?

avatar image carnivoris · Jul 13, 2015 at 02:17 AM 0
Share

I do get this error when I try to use AllViaServer, though

 TargetParameterCountException: parameters do not match signature
 System.Reflection.$$anonymous$$ono$$anonymous$$ethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Reflection/$$anonymous$$ono$$anonymous$$ethod.cs:188)
 System.Reflection.$$anonymous$$ethodBase.Invoke (System.Object obj, System.Object[] parameters) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Reflection/$$anonymous$$ethodBase.cs:115)
 PhotonView.ExecuteComponentOnSerialize (UnityEngine.Component component, .PhotonStream stream, .Photon$$anonymous$$essageInfo info) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonView.cs:530)
 PhotonView.SerializeComponent (UnityEngine.Component component, .PhotonStream stream, .Photon$$anonymous$$essageInfo info) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonView.cs:440)
 PhotonView.SerializeView (.PhotonStream stream, .Photon$$anonymous$$essageInfo info) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonView.cs:337)
 NetworkingPeer.OnSerializeWrite (.PhotonView view) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:3286)
 NetworkingPeer.RunViewUpdate () (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:3207)
 PhotonHandler.Update () (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonHandler.cs:90)
 

Here's the new code I'm working with:

     public void roundCountdown()
     {
         GetComponent<PhotonView>().RPC("roundCountdown_RPC", PhotonTargets.AllViaServer);
         Debug.Log("Running round countdown");
     }
 
     [RPC]
     void roundCountdown_RPC()
     {
         Debug.Log("Running round countdown RPC");
         roundStartScreen = GameObject.Find("RoundStartScreen(Clone)");
         roundStartScreen.transform.GetChild(0).GetComponent<Text>().text = "Round Starting In";
         //InvokeRepeating("decreaseTimeRemaining", 1.0f, 1.0f);
         StartCoroutine(countdownEnum());
 //        Debug.Log("Time Remaining: " + niceTime);
     }
 
     IEnumerator countdownEnum()
     {
         Debug.Log("countdownEnum");
         yield return new WaitForSeconds(1);
         roundCountdownTimer--;
         roundStartScreen.transform.GetChild(1).GetComponent<Text>().text = roundCountdownTimer.ToString();
         if (roundCountdownTimer >= 0) { 
             StartCoroutine(countdownEnum());
         }
     }

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

22 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

Related Questions

[Photon] Restart scene rpc doesn't work 1 Answer

I'm trying to generate a random key and share it with other players when they join the game i'm using PUN. it's not working please help! 0 Answers

Accessing the different position of a game object with same tags 1 Answer

Photonview "this" does not exist in current context 0 Answers

Destroying the bullet over a photon network 4 Answers

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