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 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 something useful (like the gameobject it's attached to). I was thinking 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, something 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 think the correct way to implement this 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 this 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

So to clarify, assign each player gameobject an int, and handle everything from within the player script itself?

avatar image PatriceVignola · May 12, 2015 at 02:21 AM 0
Share

Yes, exactly. You can handle everything in the player script itself just fine, but later you might want to have an additional layer if you ever want your game to be player either online or offline, but that's beyond the scope of the question.

Anyways, you can assign each player gameobject a unique int, and in your Game$$anonymous$$anager or somewhere appropriate, you store the array of players that's going to be the same for everyone.

avatar image Lance2120 · May 12, 2015 at 04:17 PM 0
Share

I see, thank you

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 machines a simple player number in a RPC call soon as they each connect.

once you have that, everything else is simple.

when a player makes his selection, I manually include the player number somewhere in the RPC call. this makes it easy for all the connected machines 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.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Convert Network.ViewID to Int 1 Answer

UNET Server not setting [SyncVar] 0 Answers

Brute Force Search Algorithm 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