Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 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.

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

How does the synchronization work with Photon Pun RPCs and stream.IsWriting? 0 Answers

Best Solution for Multiplayer Shooting 1 Answer

Photon enable/disable objects for 1 player but shows for all player views 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