Comments (5)
Actually something else in the documentation is quite confusing:
After listing the 'Compile-time targets' there is a note stating: "While client-to-client RPCs are supported, it is important to note that there are no direct connections between clients. When sending a client-to-client RPC, the RPC is sent to the server, that acts as a proxy, and forwards the same RPC message to all destination clients."
That's fine, makes sense to me however, the code underneath is as follows:
// what is the point of PingRpc? why not call PongRpc directly since it will send to .NotServer and do the same thing as both of these methods combined?
[Rpc(SendTo.Server)]
public void PingRpc(int pingCount)
{
// Server -> Clients because PongRpc sends to NotServer
// Note: This will send to all clients.
// Sending to the specific client that requested the pong will be discussed in the next section.
PongRpc(pingCount, "PONG!");
}
[Rpc(SendTo.NotServer)]
void PongRpc(int pingCount, string message)
{
Debug.Log($"Received pong from server for ping {pingCount} and message {message}");
}
void Update()
{
if (IsClient && Input.GetKeyDown(KeyCode.P))
{
// Client -> Server because PingRpc sends to Server
PingRpc(); // again no parameters passed in
}
}
from com.unity.multiplayer.docs.
@SteenPetersen In your first comment, the documentation is indeed incorrect. We'll make sure to fix that.
In your second comment, the code is stubbed in to show an example of sending a message to a server and receiving a response. It is not necessarily a useful example, so to speak, in the sense that no one would likely include this in their production code; it is over-simplified to show only what needs to be shown. Typically, a ping RPC is used to calculate round-trip time, or to check for timeouts; that logic is left out here to avoid confusing people. And typically, the pong RPC is sent to a single client as a response to that client's specific ping RPC; as the comment in PingRpc mentions, the documentation is saving that for the next section to avoid overloading with too much information at once.
You are correct that, as written, the client could indeed just send PongRpc and get the same result, but that isn't what the documentation is trying to show here. It's a bit of a contrived example, but the idea is just to show what a server RPC and a not-server RPC look like. Does that help?
@jabbacakes It might be worth trying to come up with a better example here.
from com.unity.multiplayer.docs.
Yes, that makes sense to me now that I have been working with it for a bit. Thanks for the answer :-)
from com.unity.multiplayer.docs.
For now, I've added a commit in #1253 to explain that the example code is heavily simplified to display basic properties of RPCs. I'll make a Jira ticket internally to cover improving the example code in the future.
@ShadauxCat can you fix the initial example that's missing an int? Probs just faster if you do it directly and commit to the open issue-fixes
branch.
from com.unity.multiplayer.docs.
For the sake of getting these updates in, I've merged the linked PR. Will make a note to go back and update the sample.
from com.unity.multiplayer.docs.
Related Issues (20)
- Overall Feedback - missing documentation for latest actual release - 1.7.1?? HOT 1
- Not a bug, but outdated steps to add networked prefabs HOT 1
- Enable setting NetworkVariable with&without invoking OnValueChanged. HOT 1
- Compiler error in HelloWorldPlayer.cs (docs/tutorials/get-started-with-ngo.md) HOT 1
- Spawn NetworkPrefab as a child of Scene NetworkObject make the object jump out of the hierarchy as a sibling HOT 1
- Menu button on the left up corner doesn't not work on iPhone 11 chrome. HOT 1
- Error Occur in HelloWorldPlayer class in Page of "Get Start with NGO" [1.8.0] HOT 1
- Outdated guide HOT 1
- unity multiplayer mode link wrong. HOT 1
- Just not working - server NEVER listens on port. Not on Windows, not on Linux HOT 1
- Feedback for docs/tutorials/get-started-with-ngo.md
- 2Feedback for docs/about.md
- Feedback for docs/tutorials/testing/testing_with_artificial_conditions.md HOT 2
- Feedback for docs/basics/object-spawning.md HOT 1
- Feedback for transport/workflow-client-server-udp.md
- Feedback for docs/tutorials/get-started-with-ngo.md HOT 1
- OnGainedOwnership and OnLostOwnership
- Feedback for docs/learn/rpcvnetvar.md HOT 5
- Feedback for docs/advanced-topics/serialization/serialization-arrays.md
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from com.unity.multiplayer.docs.