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 /
avatar image
0
Question by Logan76667 · Jan 17, 2017 at 10:16 PM · editormultiplayernetworkrpconline

Rpc Methods are not executed in remote client, unless Unity Editor is hosting the match.

I'm currently developing a cardgame for android, you can think of it like Hearthstone.

The problem I'm facing lies with the online component of the game. I can connect two clients with another, but the RpcMethod code is not executed in the remote client.

For now, I want each player to have a different view, each player should see his own hand and the amount of cards the opponent holds in his hands. The way I chose to do this was to make each Player object hold the player's hand as a childobject, and a gameobject which can display how many cards the opponent holds (just cardbacks, no actual card data).

To only show each player their own hand, this is the code that is executed at the first frame in Update() (so that it only executes after both players joined):

             //client find playerOBJs
             clientController.RpcFindPlayers();
 
             //hide other player's view from each player
             clientController.RpcHideOtherPlayer();
 
             //Testing this
             clientController.RpcColorMeSurprised();

And here is what those methods look like:

     [ClientRpc]
     public void RpcFindPlayers()
     {    
         GameObject[] players = GameObject.FindGameObjectsWithTag("Player");
 
         if (isServer)
         {
             myPlayer = players[0].GetComponent<PlayerController>();
             otherPlayer = players[1].GetComponent<PlayerController>();
         }
         else
         {
             otherPlayer = players[0].GetComponent<PlayerController>();
             myPlayer = players[1].GetComponent<PlayerController>();
         }
     }
 
     [ClientRpc]
     public void RpcHideOtherPlayer()
     {
         otherPlayer.transform.localScale = Vector3.zero;
     }
     
     //for testing purposes
     [ClientRpc]
     public void RpcColorMeSurprised()
     {
         DebugConsole.Log("ClientController.ColourMe()", "error");
         SpriteRenderer colourMe = myPlayer.transform.Find("ColorMeSurprised").GetComponent<SpriteRenderer>();
         if (isServer)
         {
             colourMe.color = Color.blue;
         }
         else
         {
             colourMe.color = Color.red;
         }
         DebugConsole.Log("ClientController.Recoloured!", "error");
     }

What the methods do: RpcFindPlayers() finds each of the players (in form of their PlayerController Script) on each server, and saves them for later use.

RpcHideOtherPlayer() reduces the scale of the other player to 0 in each client, meaning that the other player (meaning THEIR hand) is invisible.

RpcColorMeSurprised() changes the colour of a little sprite on each players hand, blue on the hosting client, and red on the guest client. (this is for my own testing purposes)

When I host the game (Create Internet Match) in the editor, and connect through a client, everything works perfectly as it should (see image) editor/host on the right, remote client on the left

But usually, when I try to connect two clients that are both not the unity editor, or when I host the game in the client, and connect through the editor, the functions mentioned above are not executed in the remote client!

I say usually, because this isn't even always the case. Sometimes, apparently at random, it DOES work if I connect two clients with another. Also, if I make a new build (new folder and the build has a different name), two non-editor clients do reliably connect with each other, and all code is executed properly, but after launching it a few times it simply doesn't work anymore...

I'm at a complete loss at this time, I have no idea what else I could try, I suspect it might have something to do with unity's multiplayer services, but I have no prior experience so I don't really know...

I'd be very grateful for any help I can get, and I can provide any additional information that you might need.

how-it-works-if-editor-is-host-ed.png (211.5 kB)
Comment
Add comment · Show 1
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 Logan76667 · Jan 18, 2017 at 11:52 AM 0
Share

After testing around some more, and with help from a colleague, I figured out the root of the problem: The clients are not all connected, or done loading the scene (I'm entering the game from a lobby scene) when the Rpc methods are called, so the remote client cannot catch the call in time.

If I introduce a three second delay before doing anything, the remote client can load in, and execute the methods.

Surely though there must be a better way to do this than the three second delay? I had already tried things like OnPlayerConnected to tell the server when the client is ready, but that didn't work either...

If anyone has a good solution for this, please share :)

0 Replies

· Add your reply
  • Sort: 

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

127 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

Related Questions

How to use an RPC to send an animation over the network? 2 Answers

RPC Parameter Optimization 1 Answer

When connected to a server, can other players access my static variables and/or public variables? 2 Answers

Photon Networking: RPC call doesn't work over other clients 0 Answers

Photon variable synchronization 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