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 Mulverick · Jul 22, 2013 at 10:50 AM · multiplayermodelrpcpositioningskin

Changing Model and spawning player by RPC

Hi,

I'm making a multiplayer game and I have a problem with my team spawn/ team model change

In my PlayerControl.cs script I do this to spawn and ask for changing model

     void OnLoaded()
     {
         Network.Instantiate(avatar0, transform.position + spawnHeight + blueSpawn, teamRotation, 0);
         playerClone = "Player(Clone)";
         Player = GameObject.Find(playerClone);
         networkView.RPC("chooseTeam", RPCMode.All, Player.name);
         Cctrl = Player.GetComponent<CharacterController>();
     }
 
     [RPC]
     void chooseTeam(string playerName)
     {
         GameObject skin;    
         GameObject Player0 = GameObject.Find(playerName);
         if (teamStatus)
         {
             Player0.transform.position = transform.position + spawnHeight + blueSpawn;
             Player0.tag = "BlueTeam";
             skin = (GameObject)Network.Instantiate(model1, transform.position, transform.rotation, 0);
             skin.transform.parent = Player0.transform;
             skin.tag = "BlueTeam";
         }
         else
         {
             Player0.transform.position = transform.position + spawnHeight + blueSpawn;
             Player0.tag = "RedTeam";
             skin = (GameObject)Network.Instantiate(model2, transform.position, transform.rotation, 0);
             skin.transform.parent = Player0.transform;
             skin.tag = "RedTeam";
         }
         teamStatus = !teamStatus;
     }

teamStatus is a bool on the server script, it seems that the host of the server deal correctly with this script but when a new Player connect to the server he is spawned in the same place as the host. What I want is my players to be spawned on the other teamspawn at each chooseTeam call, and then attach to them the skin of the team.

For now only the host see correctly what is happening.

Any idea ?

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
Best Answer

Answer by Briksins · Jul 22, 2013 at 11:02 AM

It is not very clear where is your server side or client side in the code example you proved, but if whatever you provide is only client side than problem is with your "teamStatus" as it is stored locally and not synced with Server and other clients

I believe your [RPC] call from server "chooseTeam(palyer)" should take not only player, but also teamStatus, and remove your: teamStatus = !teamStatus;

It is fundamentally wrong! Your server should define who belongs to which team, not client.

Comment
Add comment · Show 7 · 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 Mulverick · Jul 22, 2013 at 11:50 AM 0
Share

Well the RPC function is both in the server side script and on the client side script, I'm realy new with RPC and don't realy know how to deal with, I suppose RPC function must be on server and client.

avatar image Briksins · Jul 22, 2013 at 12:11 PM 0
Share

The logic should be:

  1. Client connect to server:

  2. Server and only server decide what $$anonymous$$m is clinet should be

  3. Server respond trough RPC to player with his decision

I didnt work with internal unity networking, ins$$anonymous$$d im using uLink, but anyway. From your script I see than on "OnLoaded" you send RPC call to clients: networkView.RPC("chooseTeam", RPC$$anonymous$$ode.All, Player.name); and each client try to decide to which $$anonymous$$m apply new joined user.

It is not good way of doing so! Ins$$anonymous$$d of it, your newly connected client should:

  1. send this RPC only to server

  2. Server decide to which $$anonymous$$m apply this newly connected user

  3. Server now multicast to all with his decision

Clients shouldn't make decision, they only take server decision as obligate instruction to fallow.

If you want to make game as P2P without authoritative server than your newly joined client will have to make decision based on how many Reds and Blue already in, and than multicast that decision to others and others will take it as obligate instructions to fallow.

it is very not good to allow each client individually decide to which $$anonymous$$m apply new user as each of them could decide different stuff by mistake or by players hack

Decision making only one object (weather it would be server in case of authoritative server or client in case of P2P) - other clients should be just notified about that decision and fallow it as obligate instruction

avatar image Mulverick · Jul 22, 2013 at 12:22 PM 0
Share

O$$anonymous$$ so I'll put here my code

Client side: void OnLoaded() { Network.Instantiate(avatar0, transform.position + spawnHeight + blueSpawn, $$anonymous$$mRotation, 0); playerClone = "Player(Clone)"; Player = GameObject.Find(playerClone); networkView.RPC("chooseTeam", RPC$$anonymous$$ode.All, Player.name); Cctrl = Player.GetComponent(); }

     [RPC]
     void chooseTeam(string playerName)
     {
        GameObject skin;  
        GameObject Player0 = GameObject.Find(playerName);
        if ($$anonymous$$mStatus)
        {
          Player0.transform.position = transform.position + spawnHeight + blueSpawn;
          Player0.tag = "BlueTeam";
          skin = (GameObject)Network.Instantiate(model1, transform.position, transform.rotation, 0);
          skin.transform.parent = Player0.transform;
          skin.tag = "BlueTeam";
        }
        else
        {
          Player0.transform.position = transform.position + spawnHeight + blueSpawn;
          Player0.tag = "RedTeam";
          skin = (GameObject)Network.Instantiate(model2, transform.position, transform.rotation, 0);
          skin.transform.parent = Player0.transform;
          skin.tag = "RedTeam";
        }
        $$anonymous$$mStatus = !$$anonymous$$mStatus;
     }

Server Side:

 bool $$anonymous$$mStatus = false;
 
     [RPC]
     void chooseTeam(string playerName)
     {
         GameObject skin;
         GameObject Player0 = GameObject.Find(playerName);
         if ($$anonymous$$mStatus)
         {
             Player0.transform.position = transform.position + spawnHeight + blueSpawn;
             Player0.tag = "BlueTeam";
             skin = (GameObject)Instantiate(model1, Player0.transform.position, Player0.transform.rotation);
             skin.transform.parent = Player0.transform;
             skin.tag = "BlueTeam";
         }
         else
         {
             Player0.transform.position = transform.position + spawnHeight + redSpawn;
             Player0.transform.rotation = transform.rotation;
             Player0.tag = "RedTeam";
             skin = (GameObject)Instantiate(model2, Player0.transform.position, Player0.transform.rotation);
             skin.transform.parent = Player0.transform;
             skin.tag = "RedTeam";
         }
         $$anonymous$$mStatus = !$$anonymous$$mStatus;
         Debug.Log($$anonymous$$mStatus);
         nbPlayer++;
     }

I'm really new on RPC, I believe you put the same RPCs in both code, if not do you think you could help me with that ?

avatar image Briksins Mulverick · Jul 22, 2013 at 12:34 PM 0
Share

omg /facepalm :)

do u listen to me or not?

in your case u have authoritative server so only server should decide to which $$anonymous$$m apply new player:

when player connects

 //all client code
 void OnLoaded(){
     networkView.RPC("RequestServerToChooseTeam", RPC$$anonymous$$ode.<server>, Player.name);
 }
 
 //server code
 [RPC]
 RequestServerToChooseTeam(string name)
 {
    //***
    //making decision to which $$anonymous$$m apply new user
    //***
    //once decided multicast RPC call to all players:
    networkView.RPC("addNewPlayer", RPC$$anonymous$$ode.all, Player.name, <player $$anonymous$$m bool>);
    //im not sure how to send several params on RPC call
    // with native unity Networking
    // with uLink u can send object array with parmas
    
 }
 
 //All Clients code:
 [RPC]
 addNewPlayer(string name, bool $$anonymous$$m)
 {
     //initialize your player at spawn point of the defined $$anonymous$$m
 }

P.S. be nice and and mark answer as accepted if you are happy with it. it is good way tho thanx people who helping you

avatar image Mulverick Mulverick · Jul 22, 2013 at 12:39 PM 0
Share

I thank you to help me on this problem, for now my problem isn't fixed, but thanks to you it is surely going to be fixed. By the way my server isn't a true server it's a Client/Server.

I did what you propose, I'm having bugs for now but I'm marking this answer as accepted because it will probably solve the problem Thanks

avatar image Briksins · Jul 22, 2013 at 01:07 PM 0
Share

You misunderstanding the concept of RPC RPC is the way to call method on remote device. RPC can be send to single target as well as multiple targets

In your case with client/server your RPCs of clients not necessarily should match RPCs on Server

If you calling from client RPC to server: "chooseTeam" it doesn't mean that client obligatory have to have this method implemented unless you want send respond from server to the method with the same name. it is absolutely 2 different environments to do not get confused im recommend you you named RPC with word "Request" once it is RPC from client to server and with word "Response" once it it RPC from server to cleint

 //Client.cs:
 some$$anonymous$$ethodToSendCallToServer(<params>)
 {
    networkView.RPC("ClientRequestChooseTeam", RPC$$anonymous$$ode.Server, <params>);
 }

 [RPC]
 serverResponseChooseTeam(<params>)
 {
    //do stuff
 }

//End of Client------------------------------------

 //Server.cs:
 [RPC]
 ClientRequestChooseTeam(<params>)
 {
     //do stuff
     //***
     //Replay to Client/Clients
     networkView.RPC("serverResponseChooseTeam", RPC$$anonymous$$ode.<Client/All>, <params>);
 }
 

once again, logic with multiple clients and one authoritative server should be like that:

Client send RPC to --> Server Server process it and replay back to --> single client or multiple clients as obligate instruction to fallow

avatar image Mulverick · Jul 22, 2013 at 01:45 PM 0
Share

Great ! now the players spawn at the right place. But their skin do not follow them... (They follow them for the actual player but if he look at an other player he just see his skin floating at spawn Point not following the player). It seems that localy the game put the skin on the player but not on the Network.

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

16 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

Related Questions

RPC call on other scene,NetworkView RPCs in other scene, 0 Answers

RPC /Standalone modes 2 Answers

How can I send RPC from one client to another client directly in multiplayer game? 0 Answers

i need help about players hands positions in 2D multiplayer card game 0 Answers

Photon - Change others player health problem 0 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