• 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 Lance2120 · May 10, 2015 at 07:07 PM · c#networkingarraynetworkviewid

Best way to access player's gameobject across network

So I'm trying to make a simple player customizer in a multiplayer game.

Currently I have:

  • Clicked button sends choice to "local" player

  • Player RPC's network manager (so network knows who wants to switch)

  • Manager RPC's the change to everyone

I can't figure out how to keep track of - and reference - the players correctly though. For example, NetworkViewID doesn't seem to be convertible to somet$$anonymous$$ng useful (like the gameobject it's attached to). I was t$$anonymous$$nking of putting the players in an array but I don't know how to implement it on a network correctly.

What am I missing?

Any help appreciated

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by PatriceVignola · May 10, 2015 at 10:24 PM

You need to assign a unique ID to each of your player, somet$$anonymous$$ng like an index starting at 0 for the first player. On all clients, keep an array of all players (it must be the exact same array). Then, when the player clicks on the button, RPC the action information to all players (or all other players) by sending the playerID:

 nView.RPC("ExecuteActionOnPlayer", RPCMode.OthersBuffered, playerID);

Then, when the other players receive the RPC message, they will execute the action based on the playerID you sent them:

 [RPC]
 void ExecuteActionOnPlayer(int playerID)
 {
     Player player = playersArray[playerID];

     // Execute "player" action here
 }

You have to make sure that the array stays the same on all clients, but it shouldn't be too hard since players don't usually get modified every frame. I t$$anonymous$$nk the correct way to implement t$$anonymous$$s is to build the array once on all connected players, and if you ever need to make a change to it, synchronize it via an RPC call. You can also send more than one ID if you want to execute an action that involves more than one player.

If t$$anonymous$$s is not what you wanted, please give us more explanation on exactly what you want to do over the network.

Comment
Add comment · Show 3 · 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 Lance2120 · May 11, 2015 at 07:47 PM 0
Share
avatar image PatriceVignola · May 12, 2015 at 02:21 AM 0
Share
avatar image Lance2120 · May 12, 2015 at 04:17 PM 0
Share
avatar image
0

Answer by toddisarockstar · May 10, 2015 at 09:49 PM

with my last multiplayer projects, I simply have the host assign the other connecting mac$$anonymous$$nes a simple player number in a RPC call soon as they each connect.

once you have that, everyt$$anonymous$$ng else is simple.

when a player makes $$anonymous$$s selection, I manually include the player number somewhere in the RPC call. t$$anonymous$$s makes it easy for all the connected mac$$anonymous$$nes to keep track of who is doing what.

then when you get to making your Arrays of player selections, obviosly the player number would be the same as the arrays index number representing the player. so it makes it very easy to assign incomming info directly into your arrays.

Comment
Add comment · 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

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Distribute terrain in zones 3 Answers

Convert Network.ViewID to Int 1 Answer

Multiple Cars not working 1 Answer

How do you instatiate a prefab from a string array? 1 Answer

Why the Network Health script is always null 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