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 linhdh · Nov 05, 2014 at 03:09 AM · authoritative server

Client's RPC call doesn't excute on server without any error log.

Hello,

I'm trying to implement an authoritative server with my game.

When my client finished loading a level, i want it to call a function in server to notify the server that it has finished loading a level. After receiving RPC call from client, server would do a RPC call on client to spawn a new hero on client. i wrote my code like this: (those 2 functions is on the same script file).

 void OnLevelWasLoaded(int level)
     {
         Debug.Log ("OnLevelWasLoaded. level = " + level);
         if (Network.isClient) 
         {
             Debug.Log ("Call OnLevelLoaded on Server");
             networkView.RPC ("OnLevelLoaded", RPCMode.Server, new object[] {networkView.owner});
         }
         else 
         {
             int i = Random.Range(0, spawnSetups.Count - 1);
             spawnInfo spawnSetup = spawnSetups[i];
             SpawnPlayer(spawnSetup.position, spawnSetup.rotation);
             playerCount++;
             playerIPs.Add(networkView.owner.ipAddress);
         }
     }


 [RPC]
 void OnLevelLoaded(NetworkPlayer player)
 {
     Debug.Log ("OnLevelLoaded");
     //Call the next step, in this case, spawn new instance of player
     int i = Random.Range (0, spawnSetups.Count - 1);
     spawnInfo spawnSetup = spawnSetups [i];
     networkView.RPC ("SpawnPlayer", player, spawnSetup.position, spawnSetup.rotation);
 }

I don't have 2 computer so i run 2 unity instances on a same computer, one is the server and other is the client who connects to server with:

 Network.Connect("127.0.0.1", 25000);

The bug is onLevelLoaded isn't excuted on server. When testing, i see client has the log:

 Call OnLevelLoaded on Server

But on the server, i don't see the log:

 OnLevelLoaded

Server don't have any error log when testing.

Please help me with this bug. Please excuse my English too :).

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 Bunny83 · Nov 05, 2014 at 03:28 AM

Are you sure that you have RunInBackground set to true? Either in the player settings or by setting Application.runInBackground to true in a script. Otherwise the other instance can't react to any kind of network communication until it got refocused again.

Next thing is you send "networkView.owner" to the server. Are you sure you (the client) actually owns that networkview? NetworkViews that are stored in scenes belong to the server. If you want to send your own NetworkPlayer to the server, use Network.player. However it's actually not necessary to send the NetworkPlayer manually since that information is available for every RPC. Just add the implicit NetworkMessageInfo parameter as last parameter. It will be "filled" by the system automatically. It also doesn't increase the bandwidth. See the examples in the manual

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 linhdh · Nov 05, 2014 at 08:38 AM 0
Share

I have already added Application.runInBackground = true in my script, and my hero which belongs to server is updated to client perfectly.

I make a prefab which contains NetworkView component, then i use Network.instantiate like this:

 void OnServerInitialized()
     {
         Debug.Log ("Server Initialized.");
         Debug.Log ("IP address:" + Network.player.ipAddress + ". Port: " + Network.player.port);
         Debug.Log ("External IP address:" + Network.player.externalIP + ". External port: " + Network.player.externalPort);
         //Create a networked network manager.
         Game$$anonymous$$anager.network$$anonymous$$anager = new GameObject("Network$$anonymous$$anager");
         Game$$anonymous$$anager.network$$anonymous$$anager.hideFlags = HideFlags.HideInHierarchy;
         Game$$anonymous$$anager.network$$anonymous$$anager = Network.Instantiate (network$$anonymous$$anagerPrefab, Vector3.zero, Quaternion.identity, 0) as GameObject;
         Debug.Log("network$$anonymous$$anager = " + Game$$anonymous$$anager.network$$anonymous$$anager == null);
         //load multiplayer level for server.
         NetworkLevelLoader.Instance.LoadLevel ("$$anonymous$$ultiPlayer", levelPrefix);
     }

I tried to add network$$anonymous$$anager object via hierarchy but this bug happens in that case so i tried to do it like this.

All RPC from server to client work normally. For example:

 void OnPlayerConnected ( NetworkPlayer player ) {
         Debug.Log ("OnPlayerConnected. playerCount= " + playerCount);
         if (playerCount < $$anonymous$$axNumberOfPlayer) 
         {
             networkView.RPC ("LoadLevel", player, new object[] {"$$anonymous$$ultiPlayer", Game$$anonymous$$anager.levelPrefix}); 
             playerCount++;
             playerIPs.Add(player.ipAddress);
         } 
         else 
         {
             Network.CloseConnection(player, true);
         }
     }

 [RPC]
     void LoadLevel(string levelname, int levelPrefix)
     {
         Debug.Log ("LoadLevel");
         NetworkLevelLoader.Instance.LoadLevel (levelname, levelPrefix);
     }

These functions are called just before OnLevelWasLoaded.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

2 Servers in one build 2 Answers

Should I worry about making an authorative server for an online multiplayer WebGL game? 0 Answers

Multiplayer jitter on client 0 Answers

Create single server for multi-platform game (pc, mobile, etc) 2 Answers

Is there anyway to disable clients GameObject instance from Server or Vice-versa? 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