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 killiantheelder · May 18, 2019 at 12:18 AM · unity 5multiplayermultiplayer-networkingclient-serverhost

Command/ClientRpc/ Help -- Need Client Commands to run!,Question About Command/ClientRpc/Client Authority

Disclaimer: I am rather new to Unity and I may be going about this the wrong way -- if you feel or think so, please tell me and help me get out of my rabbit hole!


My issue is a simple one - but I think the way we are doing things in our game is a little bit different than what I've usually been seeing in tutorials/answers. Usually I see advice to spawn new players, however we have opted to simply set the two player objects with the proper authority, as our Players have UI/Visual elements we need from scene to scene set on them. We realize now that that is probably very bad practice, and are working on reformatting our player code to only handle actual game logic inside - rather than visual elements.


We have a two player game that we've been porting to multiplayer. We would like your player to always be on the left, theirs on the right, and for that to be equally true if you are a client vs the host player.


We have a GameStateManager script that had DontDestroyOnLoad attached, and two players. The network manager script is attached to our GSM, and we have a modified network behaviour script on either player. They are both set to LocalPlayerAuthority = true.


This is how we add the players to the network:


 public override void OnServerAddPlayer(NetworkConnection conn, short playerControllerId)
     {
         GameObject player;
         short playerId;
         if (conn.address == "localClient")
         {
             playerId = 0;
             player = GameStateManager.instance.player_1.gameObject;
             GameStateManager.instance.player_1.IsMainPlayer = true;
         }
         else
         {
             player = GameStateManager.instance.player_2.gameObject;
             playerId = 1;
         }
         NetworkServer.AddPlayerForConnection(conn, player, playerId);
     }



This is how we set LocalPlayer authority:


 public override void OnStartLocalPlayer()
     {
         //base.OnStartLocalPlayer(); // I am unsure I need/want this.
         Player = GameStateManager.instance.OurPlayer;
         if (playerControllerId == 1)
         {
             ChangeGameStateFilter(GameStatus.MonsterSelection);
         }
     }


And this is the general pattern of how we run our functions:


  public void Example()
     {
         if(isServer)
         {
             RpcExample();  
         }
         else
         {
              CmdExample();
         }
     }
     
     [Command]
     public void CmdExample()
     {
         RpcExample();  
     }
     
     [ClientRpc]
     public void RpcExample()
     {
         // For example, add a monster to our player
         // This is our clients player object, we use TheirPlayer to refer to the other player
        Player = GameStateManager.instance.OurPlayer;
        Player.AddSelectedMonster();                  
     }


THe problem seems to be that no matter what I do, whenever I select a monster to choose a monster, it only gives it to the host player. I would like to click the monster on the correct screen and add it to our players monsters.


I know this is a somewhat open-ended question - mainly looking for advice/best practice direction so I can help drag our game out of the current miasma it's stuck in. If I can offer any more information or answer anything, please let me know.


Extra Credit -- If my players both have local authority and are set to islocalplayer correctly, do I need the base.OnStartLocalPlayer()? ,

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

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

267 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 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 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 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 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 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 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 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 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 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 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 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 avatar image avatar image avatar image

Related Questions

What to do when user clicks back on google play games realtime multiplayer auto-match ui ? 0 Answers

Photon network won't join random room with a custom property 0 Answers

UNET Networking: Changing Players texture 0 Answers

Photon RPC is not working in photon? 2 Answers

How do I create a multiplayer turnbased game server? 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