• 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
1
Question by Somedays · Jul 22, 2013 at 09:03 PM · networkingmultiplayernetworkrpcstatic

When connected to a server, can other players access my static variables and/or public variables?

1.When I connect to a server and I have a few objects in my scene (NOT network instantiated) and I look them up using GameObject.Find(), is there a chance I grab someone ELSE's object that isn't mine?

2.Also how do static variables work across networks inside of the same scripts. If I set my character's hair color to red in my menu scene, but then load up the game scene and access MenuScript.hairColor, will other players on the network be able to access that red color or will they access whatever color they picked?

3.As of right now when players connect to my server, players view other players with the same material as themselves. (If I pick red, all players are red w$$anonymous$$le on their screen everyone is blue because they picked blue.) Why does t$$anonymous$$s occur? does t$$anonymous$$s have to do with me using static variables to store the player's chosen color?

If you have a solid understanding of how networking works please share your knowledge! When players connect to the server I call an RPC function called UpdateAppearance() that is buffered and sent to all. t$$anonymous$$s function is attached to the player and changes it's color based on the variable of their chosen color. But everyone ends up viewing their own color on everyone instead of whatever color other players picked.

Comment
Add comment · Show 2
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 Application · Apr 01, 2018 at 05:57 PM 0
Share

Hey I have a question if I "link up" 2 Scripts about public static in a player, can affect also other players?

For example: I go, (public static bool walk = true) -> then go all players on the server? Although only I press "w"?

->Of course I have not used this, but einaml was public static unvermeindlich ,I have also a qustion to this :

if i have 2 scripts on a player "connected" with a public static bool or else (all in one player), does it Change other Players bools ? Or not... ?

Sorry for my english skills XD

avatar image meat5000 ♦ Application · Apr 01, 2018 at 05:59 PM 0
Share

Ask a fresh question

2 Replies

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

Answer by Owen-Reynolds · Jul 22, 2013 at 09:47 PM

No.

The programs on different mac$$anonymous$$nes may have the same code, but they count as completely different programs. Like two people playing their own copies of (single player) CutTheSnake 2.6.1. They will never share variables unless you do somet$$anonymous$$ng special in code to make that happen.

An RPC function is that special somet$$anonymous$$ng. It sends a message to the other mac$$anonymous$$ne saying somet$$anonymous$$ng like "$$anonymous$$, I'm sending t$$anonymous$$s for redDog(clone) with ID:346. You should also have a redDog(clone) ID:346 over there. If you get t$$anonymous$$s, could you set iStatus to 7?"

The other magic is Unity will auto-send network messages (basically RPCs) to copy position, rotation ... of "network spawned" transforms. But that's all it does -- can't be extended to auto-copy any other properties or script vars. You have to RPC those. If they change infrequently, you can send them only when they change.

A clever trick is to make changeCol be an RPC function. Then remember to never just set color=c2;. Instead, always use network.changeCol(c2, All); (I forget the exact syntax.) That tells Unity to "write a letter" (RPC) to all the other players and you, asking them to run changeCol on their copy.

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

Answer by Somedays · Jul 23, 2013 at 12:06 AM

I FIXED IT! All I needed to do was pass the correct material id through the RPC function. I wasn't using any parameters before, and wit$$anonymous$$n the function setting the material based on a variable saved in player prefs. Feels good to finally have it working after 3 DAYS of t$$anonymous$$s bug haha!

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

17 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

Related Questions

Multiplayer issue - players view others as themselves with same material 1 Answer

How To Deal With Lingering Prefabs in Multiplayer Scene ? 0 Answers

RPC custom server best practice 1 Answer

How to use an RPC to send an animation over the network? 2 Answers

Multiplayer - Selected character to Network.guid? 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