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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by drfrev · Feb 11, 2014 at 03:20 AM · c#networkingserverrpcclient

RPCMode.Server works in one spot but not another

Hello, so my problem which I just can't seem to solve is that I have the line

 networkView.RPC("SOMERANDOMFUNCTION",RPCMode.Server);

in two places in a script but it only runs in one place. That is what really gets me. I have two scripts one is server.cs and the other is client.cs. Server.cs runs only on the server and client.cs runs on every machine (including server). I have two RPC calls in client.cs:

 networkView.RPC("sendLevelHasLoaded",RPCMode.Server);
 
 networkView.RPC("requestJoin",RPCMode.Server);

The first one runs, the second one will not. I have no idea why.

Below are the snippets of my code

client.cs

     void OnLevelWasLoaded(int level) {
         if (!enabled) {return;}//only run if the script is enabled
         Network.isMessageQueueRunning = true;
         Network.SetSendingEnabled(0,true);
         if (Network.isServer) {
             cont_server.setPlayerHasLoaded(networkView.owner);    
         } else {
             networkView.RPC("sendLevelHasLoaded",RPCMode.Server);
         }
     }
     
     int lastLevelPrefix = 0;
     [RPC]
     void loadMap(string inMap, int levelPrefix) {
         lastLevelPrefix = levelPrefix;
         Network.SetSendingEnabled(0,false);
         Network.isMessageQueueRunning = false;
         Network.SetLevelPrefix(levelPrefix);
         
         Application.LoadLevel(inMap);
     }

The above works fine the below does not.

     void sendRequestJoin() {
         if (Network.isServer) {
             cont_server.allowPlayer(networkView.owner);    
         } else {
             networkView.RPC("requestJoin",RPCMode.Server);
         }
     }
     
     [RPC]
     public void requestAccept() {
         Debug.Log ("From Server - Accepted");
     }
     
     [RPC]
     public void requestDenied() {
         
     }
     
     void leaveServer() {
         networkView.RPC("leaveServer",RPCMode.Server);
     }
     
     // Use this for initialization
     void Start () {
         sendRequestJoin();
     }

Server.cs

     int levelPrefix = 0;
     void sendLoadMap(string inMap) {
         Network.RemoveRPCsInGroup(0);
         Network.RemoveRPCsInGroup(1);
         levelPrefix++;
         networkView.RPC("loadMap",RPCMode.AllBuffered,inMap,levelPrefix);
     }
     
     public void setPlayerHasLoaded(NetworkPlayer inId) {
         Debug.Log ("howdy"+inId);//THIS WILL PRINT WITH PROPPER IDs
         //everyoneHasLevelLoaded = true;
         for (int i = 0; i < players.Count; i++) {
             if (players[i].owner == inId) {
                 players[i].hasLoadedLevel = true;    
             } else if (!players[i].hasLoadedLevel) {
                 everyoneHasLevelLoaded = false;
             }
         }
     }
     
     [RPC]
     void sendLevelHasLoaded(NetworkMessageInfo info) {//the client will send this once they have loaded their level
         setPlayerHasLoaded(info.sender);
     }

Again the above will run but below will not.

     public void allowPlayer(NetworkPlayer inId) {
         if (networkView.owner == inId) {
             cont_client.requestAccept();
         } else {
             networkView.RPC("requestAccept",inId);//accept them
         }
         //add them to the player list
         players.Add(new player(inId));
     }
     
     [RPC]
     void requestJoin(NetworkMessageInfo info) {
         Debug.Log ("CHERRO");//THIS WILL NEVER PRINT
         if (true) {//allow everyone for right now
             allowPlayer(info.sender);
         }
     }
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 sumeetkhobare · Feb 11, 2014 at 08:50 AM 0
Share

I observed a thing while working on my project once that the flow of intializing objects while starting the game takes some time, so I prefer not to make any network calls in the Start() and Awake() function. because you can't tell if the object is ready to receive or not. So make your call in other functions.

 void Start () {
     sendRequestJoin();
 }

try avoiding this and adding it to Update or something else like OnPlayerConected or OnConnectedToServer().

avatar image drfrev · Feb 11, 2014 at 11:10 AM 0
Share

You sir are a gentleman and a scholar! That was the problem, thank you so much.

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

18 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

Related Questions

Network how to send data/activate function 1 Answer

ClientRpc not called on Client 1 Answer

Totally lost with UNET - Client to Server Networking 3 Answers

Networking: RPC To Specific Player? 1 Answer

RPC not being called 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