Search Unity

Host and Client issue with gameobjects

Discussion in 'Netcode for GameObjects' started by VKyuzel, Mar 21, 2023.

  1. VKyuzel

    VKyuzel

    Joined:
    Mar 6, 2022
    Posts:
    21
    Hello,

    I'm creating a card game (1vs1) with a tile board.

    I'm having an issue between Hoster and Client:
    When I play a card, I call the server to ask if I can create the card, than the server does a ClientRpc
    that create the card to every player.
    And that works perfectly.
    The issue is coming along if I start to work with gameobjects edited by Server in cascade:
    upload_2023-3-21_10-30-33.png
    In the image you can see method PushCardFromTable: inside has a ServerRpc (the method move the card from tile 1,1 to tile 1,2).
    The below method, TriggerPushEnemyEffect, has the current issue:
    if I call TriggerPushEnemyEffect from Host, the Hoster see the card in tile (1,2)
    meanwhile if I call TriggerPushEnemyEffect from the Client, I see the card in tile (1,1) (until the whole funcion is done).

    AS you can imagine, I want work with the correct tile but I can't if they have different behavior. I'm using a check like:
    if (!NetworkManager.Singleton.IsClient)
    {
    return;
    }

    To be sure that hoster is working as client but even that doesn't change anything.
    Maybe I should do something like: "until the PushCardFromTable method is not done, don't run code below"
     
  2. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    5,892
    Can only advise in general. Most of the time when someone does a board/card game they imagine every step of an action to be network synchronised, including effects and animations or even the UI.

    However, if you play a card that does something like move across the table and spawn an effect, all you really need is a PlayCard rpc and a confirmation. Movement and effect are done on each client locally. The same with the end result, ie when two cards „fight“ the result of that fight is to be calculated by the server when the fight begins so each client knows what the end result will be and can issue the animations and effects accordingly locally since they have no effect on the game state.

    In short: only synchronize game state. Everything else that is merely a consequence of a game state change should run locally.
     
    VKyuzel and RikuTheFuffs like this.