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
0
Question by hmendes00 · Jun 15, 2016 at 06:19 AM · networkrpcmasterserver

RPC Client and Server playing

Hi everyone,

I am implementing a multiplayer game and I am using Networkview.RPC() to make my calls.

The game should have two players.

I think I am a bit confuse about who's the server and the client. Here's what I have:

  • Master Server hosted in Digital Ocean

  • My Code to create room with MasterServer.RegisterHost()

  • Code to find match and connect

All this works (I am not sure if it works as should)..

My question is:

Should the server be the player also? because when one person on his phone creates the match, he will be the server.. the person who connected to the created game will be the client..

my RPC is sent to all, like so:

networkView.RPC("doMove", RPCMode.All, null);

when the server do the movement, I can see it being updated in the other phone (the client).. but the opposite doesn't work.. when I do the movement with the client it doesn't update the server.

Can someone explain me if I really understood this game logic between the server and client and what is wrong?

Any help will be very appreciated. Thanks.

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

Answer by Orami · Jun 15, 2016 at 06:39 AM

You are using obsolete functions. Unet is actually pretty good once you get used to it. I will try to give a quick overview of UNet if you wish to try to use it.

 [Command] //this lets a client call code on the server's copy of the object that the script is attached to as long as it has local authority to the client... code called in the function will be called on the server's object only MUST be named with Cmd..
 example:
 [Command]
 void CmdmyFunction()   //maximum of one parameter that must either be a native type or a      struct/class of native types 
 
 [ClientRpc]  //this lets a server call code on the client... code called in this function will be run on the client MUST be named with Rpc
 example:
 [ClientRpc] 
 void RpcmyFunction2()   //maximum of one parameter that must either be a native type or a     struct/class of native types 


 [Server] //code will only execute on the server it will NOT EXECUTE if you call the function on the client
 example:
 [Server]
 void serverOnlyFunction()

 [Client] //code will only execute on clients it will NOT EXECUTE if it is called on the server.
 example:
 [Client]
 void clientOnlyFunction()

 class myClass : NetworkBehaviour
 {
     [SyncVar] //only usable on native types will automatically sync from server to client
     int health;
 }

you may use isServer and isLocalPlayer to determine what you are. Note that since you are hosting the server and also playing on that that both of these will return true on the hosting phone. Hopefully this will help you if no one responds to the old code which I don't know well enough unfortunately.

Comment
Add comment · 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 jdean300 · Jun 15, 2016 at 07:18 AM 2
Share

Should be noted that saying a command lets a client call code on the server means only the clients local player object - no other objects existing on the client can call commands.

avatar image Orami jdean300 · Jun 15, 2016 at 07:37 PM 0
Share

Will edit to make it clearer.

avatar image hmendes00 · Jun 15, 2016 at 12:24 PM 0
Share

really nice help, @orami. I'll update my code according to UNet.

avatar image Logan76667 · Jan 19, 2017 at 03:31 PM 0
Share

"Note that since you are hosting the server and also playing on that that both of these will return true on the hosting phone. "

This is a very important aspect, and something I wasn't sure about before, thanks!

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Send RPC in 2 scene 0 Answers

Clients are not disconnected when Master Server goes shut down 1 Answer

How to get a gameObject having viewID? 1 Answer

Sending Network player info with RPC 1 Answer

Best way to synchronize game scores? 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