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 paskal007r · Apr 29, 2014 at 10:21 AM · networkingrpcclient-server

how to ask Server for a value?

I need to ask a lock from client to server. Basically it would be a get function but RPC doesn't support that.

One solution would be to have a dedicated variable, but there is a wide number of locks I can get and I need to specify the return variable in the client. Also, the actual request for the lock comes from a range of classes that use the lock handler class.

A local version is:

 public PhaseLock getLock(GamePhases phase){
         PhaseLock newLock=generateLock(phase);
         lockHolder[phase].Add(newLock.id);
         return newLock;
     }

Someone knows a way to do it in a client-server environment without writing a thousand lines of code to store and pass the identity of the script (and the gameobject instance) that requested the lock?

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
0
Wiki

Answer by hubatish · Apr 29, 2014 at 12:49 PM

Why is it difficult to know which gameobject/script sent the RPC? Generally, my clients and server have near duplicate scenes - or at least they should each have an instance of whatever object you need to put a lock on. So knowing the correct script/gameobject to send to is as simple as passing making an RPC call from a script watched by a NetworkView on the client being received by the same script on the server.

To "get" the information from the server is really two calls - one to request the data from the server and one to send it back. So your code might look something like this:

 private void RequestLock()
 {
     networkView.RPC("GetLock", RPCMode.Server, "LockType");
 }

 [RPC]
 public void GetLock(string lockType, NetworkMessageInfo info)
 {
     //get the correct lock...
     networkView.RPC("ReceiveLock", info.sender, aLock);
 }

 [RPC]
 public void ReceiveLock(string aLock)
 {
     //do good stuff with the lock
 }

The NetworkMessageInfo parameter provides which player and which networkView sent an RPC call. If it's difficult to reconstruct the lock from strings or some array of basic objects, you might want to look into OnSerializeNetworkView, which you can use to pass more complicated objects.

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

21 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

Related Questions

A nontrivial question: Call server procedure by wamp protocol 0 Answers

Rpc Can't be called on client - Problem with client, works on server 1 Answer

Changing variable value Network 1 Answer

How to fix "ClientRpc call on un-spawned object" error, using UNET 2 Answers

Standard ClientRPC not called on client 1 Answer


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