Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Join us on March 30, 2023, between 5 am & 1 pm EST, in the Performance Profiling Dev Blitz Day 2023 - Q&A forum and Discord where you can connect with our teams behind the Memory and CPU Profilers.
    Dismiss Notice

Resolved [Netcode] is there an option for a client to request data from the server?

Discussion in 'Multiplayer' started by bklotzman, Nov 9, 2022.

  1. bklotzman

    bklotzman

    Joined:
    Feb 21, 2020
    Posts:
    2
    I'm in a situation where a ServerRpc that can return a value would be super helpful, but of course this is not allowed. So I'm wondering if there is a way that I'm just missing for a client to request some data that only the server has?

    If not...let me give some more details on the situation, maybe I've just setup my thinking all wrong. I have a hex-based top down strategy war game (think the old Avalon Hill table top wargames) that I wrote a couple of years ago that just did hot-seat play.

    I'm now basically re-writting my game for multi-player using the official Netcode for GameObjects.

    As written originally I'd separated all the data classes from their visual GameObjects so as an example I have a "Fleet" class that is not a monobevaior that has all the data about a fleet and actions it can do. There is a separate class for the gameobject which controls the visual representation of the Fleet on screen.

    Since I wanted everything Server Owned...seemed like this would work just fine to bring over as is. But what i'm finding is there are times when the client side game objects (usually UI display info panels), need some data from the server side classes that isn't there on the client, and looking for the best ways to resolve that. Didn't seem like a good idea to turn all those data classes into NetworkBehaviors and then have to sync a lot of data that the clients don't really need

    I can provide a much more comprehensive example if that didn't make sense.
     
  2. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    2,101
    Client: RequestSomeDataServerRpc()
    Server: RespondWithDataClientRpc(<your data>)
    ;)
     
  3. bklotzman

    bklotzman

    Joined:
    Feb 21, 2020
    Posts:
    2
    oh geez, I knew I was being an idiot...
    Thank you...problem solved...