• 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
Question by diohellfire · Apr 15, 2014 at 12:10 AM · networkingnetworkserver

other players and the server does not receive networkView.RPC

Hello, I have a problem, I made a server and a client with login and password, so far everything works, but for some reason, when I change the scene, after instantiating the player, if I call networkview.RPC, the server and other clients do not receive the RPC, and also returns no error, the instantiated object has NetworkView, following the example code of my player (cube):

 using UnityEngine;
 using System.Collections;
 
 public class Characters : MonoBehaviour {
     
     public int id;
     public string name;
     public int level;
     public int sex;
     public int classNumber;
     public string account;
     public Vector3 pos;
     public Quaternion rot;
     public int map;
     public TextMesh text;
     public bool viewName = true;
     public bool isMine = true;
          
     void Start () {
         transform.position = pos;
         transform.rotation = rot;
         if(!viewName)
         text.text = "";
         else
         text.text = name;
     }        
 
     void Update () {
         
         pos = transform.position;
         rot = transform.rotation;
         
         isMine = networkView.isMine;
         if(isMine)
         {
             networkView.RPC("receiveData",RPCMode.All,transform.position,transform.rotation,name,level,classNumber,sex,networkView.viewID);
             
         }
     }
     
     [RPC]
     void receiveData(Vector3 pos,Quaternion rot,string name,int level,int classNumber,int sex,NetworkViewID view)
     {
         if(!isMine)
         {
             transform.position = pos;
             transform.rotation = rot;
             this.name = name;
             this.level = level;
             this.classNumber = classNumber;
             this.sex = sex;
             viewName = true;
         }
     }
     void OnApplicationQuit()
     {
         networkView.RPC("PlayerLeave",RPCMode.Others,account);
         networkView.RPC("SavePlayer",RPCMode.Server,id,level,classNumber,pos,map);
     }
     
     [RPC]
     void PlayerLeave(string login)
     {
     }
     [RPC]
     void SavePlayer(int id, int level,int classNumber, Vector3 pos, int map)
     {
         
     }
 }


Thanks.

Comment

People who like this

0 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 Benproductions1 · Apr 15, 2014 at 12:20 AM 0
Share

Please remove the massive amounts of excess witespace from your code. Are you getting any errors or warnings on any of the clients/server?

avatar image diohellfire · Apr 15, 2014 at 12:44 AM 0
Share

Removed, don't have any errors or warnings...

1 Reply

· Add your reply
  • Sort: 
avatar image

Answer by akauper · Apr 15, 2014 at 08:21 AM

I believe you have some networking logic errors here.

All players have a gameobject with this script in their scene. Within Update all players set the "isMine" variable equal networkView.isMine. Then all players send an RPC to ALL other players if the networkview is theirs, which, for each of them, it is.

Basically everyone is sending the "receiveData" RPC every frame and everyone is receiving everyone else's "receiveData" RPC every frame.

I think what you are experiencing is a lockup. Where players positions and other values are so constantly being set to the same value that no movement or change is possible.

Comment

People who like this

0 Show 4 · 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 diohellfire · Apr 15, 2014 at 02:06 PM 0
Share

think I'm doing something wrong related to viewID explain me something, networkView.RPC only sends to the objects with the same viewID? because the tests I did, it only works with objects with the same viewID

avatar image akauper · Apr 15, 2014 at 06:38 PM 0
Share

Yes. Only to objects with the same viewid

avatar image diohellfire · Apr 15, 2014 at 08:18 PM 0
Share

I understand now, but it seems the problem is that the object is instantiated on the client with the viewId that is different from the server

avatar image akauper · Apr 15, 2014 at 08:59 PM 0
Share

Think of it this way:

Client1, Client2, and Server all have a gameobject in their scene. This gameobject has a NetworkViewID attached to it.

When using Network.Instantiate() or allocating a ViewID the server sets the internal information on the networkview of each of those players (including the server). It sets the 'owner' variable to whoever called Network.Instantiate() or Network.AllocateViewID(). It then sets the NetworkViewID to the same value on all gameobjects.

You come along and are trying to, lets say, update the value of a variable (a boolean variable well call exampleVar). Client 1 executes (within a method): exampleVar = true; networkView.RPC("ExampleMethod", RPCMode.OthersBuffered, exampleVar);

Unity then looks for an [RPC] tagged method named "ExampleMethod" on any script attached to a GameObject with the SAME NetworkViewID as the sending client's gameobject.

Networking is about SYNCING two or more games togethor. NetworkViewID acts as a way for each game to 'know' that their gameobject is supposed to be the same as the other gameobjects with the same NetworkViewID

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

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

Unity networking tutorial? 6 Answers

FPS drops to 30 when I use MasterServer.RegisterHost, WHY!? 1 Answer

Is there a way to notify to the app once client has connected to server? 2 Answers

Create separate Unity project for headless server 1 Answer

Unity dedicated server for validating data and handling data from many clients 2 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