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
2
Question by TomNCatz · Dec 18, 2015 at 07:42 PM · c#networkingunity5client-serverunity 5.2

UNet ClientRPC does not fire

Unity 5.2.3f1 Windows 10 C#

I am basically making a multiplayer board game. Players need to have a stack of tiles they can play, move, etc. that all have independant stats. I have set up a player network object with the NetworkBehaviour shown below. ass you can see most of my functions are structured fairly similarly, but I am getting VERY different results.

SceneChange and MoveTile work perfectly one bothe the client and server, as well as FRROM the client and server. StackDeck and SyncTile are another matter. Both of them execute the Command only. By this I don't mean that the code doesn't work right for the ClientRpc call, I mean the call doesn't happen. Anywhere. Client or server, Unity editor or built project, developer build or not, NOWHERE does even the debug call give output from those two RPC calls, nor are errors thrown.

I am at a loss. I have been changing things back and forth trying to find a cause, or even just what makes the two functions that work different, but I've come up short. Any assistance would be greatly appriciated.

 using UnityEngine;
 using UnityEngine.Networking;
 using System.Collections;
 using System.Collections.Generic;
 using TTools;
 
 public class TilesNetworkManager : NetworkBehaviour
 {
     public static TilesNetworkManager instance;
     public static int netLock = 0;
 
     
     private NetworkManager netManager;
 
 
     void Awake()
     {
         DontDestroyOnLoad( gameObject );
     }
 
     void Start()
     {
         instance = this;
         netManager = GameController.Instance.netManager;
     }
 
     public static void SceneChange( string scene )
     {
         instance.CmdSceneChange( scene );
     }
     
     public static void StackDeck( TileDeck savedDeck )
     {
         netLock++;
         instance.CmdStackDeck( true, savedDeck.ToString() );
     }
     
     public static void MoveTile( Tile tile, BoardSlot slot )
     {
         instance.CmdMoveTile( tile.gameObject, slot.name );
     }
     
     public static void SyncTile( GameObject tile )
     {
         instance.CmdSyncTile( tile );
     }
 
 
     [Command]
     public void CmdSceneChange( string scene )
     {
         netManager.ServerChangeScene( scene );
     }
 
     [Command]
     public void CmdStackDeck( bool playerA, string deckString )
     {
         if( Board.Instance.deckA.Count > 0 )
         {
             Debug.Log("Deck B");
             TileDeck savedDeck = new TileDeck();
             savedDeck.FromString( deckString );
             Board.Instance.StackDeck( false, savedDeck );
         }
         else
         {
             Debug.Log("Deck A");
             TileDeck savedDeck = new TileDeck();
             savedDeck.FromString( deckString );
             Board.Instance.StackDeck( true, savedDeck );
         }
         RpcStackDeck(false,deckString);
         netLock--;
     }
     
     [Command]
     public void CmdMoveTile( GameObject tile, string slot )
     {
         Debug.Log("Server Move");
         RpcMoveTile( tile, slot );
     }
     
     [Command]
     public void CmdSyncTile( GameObject tile )
     {
         Debug.Log("Server Load Tile");
         NetworkIdentity objNetId = tile.GetComponent<NetworkIdentity> ();        // get the object's network ID
         objNetId.AssignClientAuthority (connectionToClient);    // assign authority to the player who is changing the color
         RpcSyncTile( tile );                                    // usse a Client RPC function to "paint" the object on all clients
         objNetId.RemoveClientAuthority (connectionToClient);    // remove the authority from the player who changed the color
         //GetComponent<Tile>().LoadTile( Board.Instance.roster[ID], ID );
     }
     
     [ClientRpc]
     public void RpcStackDeck( bool playerA, string deckString )
     {
         Debug.Log("Deck B made here");
         TileDeck savedDeck = new TileDeck();
         savedDeck.FromString( deckString );
         Board.Instance.StackDeck( false, savedDeck );
         netLock--;
     }
     
     [ClientRpc]
     public void RpcMoveTile( GameObject tile, string slot )
     {
         Debug.Log("Client Move");
         Tool.StartCoroutine( Board.Instance.MoveTile( tile.GetComponent<Tile>(), Board.FindSlot(slot) ) );
     }
     
     [ClientRpc]
     public void RpcSyncTile( GameObject tile )
     {
         Debug.Log("Client Load Tile");
         int id = tile.GetComponent<TileNet>().ID;
         tile.GetComponent<Tile>().LoadTile( Board.Instance.roster[id], id );
     }
 }
 
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

2 Replies

· Add your reply
  • Sort: 
avatar image
5

Answer by JohnBubriski · Aug 25, 2016 at 02:45 PM

See the answer here: http://answers.unity3d.com/questions/1180855/why-is-this-clientrpc-not-executed.html

"I was calling the ClientRpc method before the game player objects on clients were properly set up by OnLobbyServerSceneLoadedForPlayer. To fix it I just waited with calling the ClientRpc until after the start method was invoked on all client gameplayer objects."

I confirmed that something like this is the problem/solution. In my case I used OnStartLocalPlayer() in my player controller to call a Command method on the server, which in turn called an Rpc method on the clients. Trying to call Rpc methods in other ways resulted in nothing happening, probably because there were no players ready, including the local one!

To be more specific, I'm creating a multiplayer game where the map is procedurally generated by the server each session.

Player code snippet:

 public override void OnStartLocalPlayer()
 {
     _buildingManager = FindObjectOfType<BuildingManager>();

     _buildingManager.CmdPlayerReady();
 }

BuildingManager code snippet (Thing that sets up the map):

 [Command]
 public void CmdPlayerReady()
 {
     RpcSetupMap();
 }
 
 [ClientRpc]
 public void RpcSetupMap()
 {
     Debug.Log("Spawn Blocks.");
     SpawnBlocks();

     Debug.Log("Spawn Buildings.");
     SpawnBuildings();
 }

In case anybody asks, I'm also using Random.InitState(Seed); to generate the same map on each client. Seed is a [SyncVar ] that gets randomly generated by the server each session.

I'm on version 5.4.0f3 Personal.

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 spartawhy117 · Dec 04, 2018 at 01:12 PM 0
Share

Building$$anonymous$$anager is sever authority?if it is ,how it can use command function?

avatar image
1

Answer by nsmith1024 · Jul 05, 2016 at 07:03 PM

I have the same problem in the latest version of Unity 5.4.0b23

[Command] works but not [clientRpc], same goes for the previous Unity release.

I cant understand how everybody is not seeing this huge glaring bug. The networking rpc calls are just not working, but strange nobody seems to care. But i cant do any work because of this right now since my game uses network heavily and networking clientRpc functions dont work at all.

Is Unity still in business or are they closed down?

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

59 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

Related Questions

ClientRpc Function not being carried out on all clients in Unity3d c# 0 Answers

Qos type ReliableFragmented channel, won't fragment our stream 2 Answers

Unet: Client/Server end up with two different animations 0 Answers

How to synchronize disable and enabling game objects over the network? 0 Answers

Destroying entire parent object on one client but on the other destroying just the child. 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