GithubHelp home page GithubHelp logo

Comments (5)

SteenPetersen avatar SteenPetersen commented on May 20, 2024

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.

ShadauxCat avatar ShadauxCat commented on May 20, 2024

@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.

SteenPetersen avatar SteenPetersen commented on May 20, 2024

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.

jabbacakes avatar jabbacakes commented on May 20, 2024

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.

jabbacakes avatar jabbacakes commented on May 20, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.