Search Unity

Third Party Mirror Networking : Pick & Drop items

Discussion in 'Multiplayer' started by xtoc, Jan 14, 2021.

  1. xtoc

    xtoc

    Joined:
    Jun 3, 2017
    Posts:
    15
    Hi,

    I'm ussing mirror lib for networking.
    I didn't find any good solution yet for my problem :

    Lets say that there are 4 player in the game.
    Within the scene there is 1 cube that can be pickup or dropped.
    What is the best way to archive this?

    I've found a link from mirror itself, but their they spawn a new item instead....
    https://mirror-networking.com/docs/Articles/Guides/GameObjects/PickupDropChild.html

    (I would like to keep the current object instead)

    Thank you in advance!

    Kind regards,
    Kurt
     
  2. orzech123

    orzech123

    Joined:
    Mar 12, 2018
    Posts:
    17
    Did you find an anwer? I encounter huuuge issues while assigning/removing object authority when want to keep current object like you.
     
  3. e_Zinc

    e_Zinc

    Joined:
    Oct 31, 2019
    Posts:
    19
    We're currently making a multiplayer game that involves a looooot of objects, so I have some battle-tested advice for you. Here's a video of our game, made in Mirror:


    First, I'd create some sort of a equip manager on the player object. This would be networked and act as a vessel for replicating what's being held. You can pair this with another networked inventory class if you'd like to have multiple items that you can swap between.

    For pickups, this equip manager sends out requests to the server to request picking up an item. Because players can clash when spam picking the same item, the server should ultimately be the one that resolves conflicts.

    If the server determines it's a legal pick up, it assigns the authority of the item to the player that picked it up. This way, you can call functions on the item freely as the client holding the item as well as have the option to set its transform properties clientside to replicate to others.

    Then, it sets that player's equip manager to set the current pickup as the currently held item. The cleanest but most non performant way to replicate this transform change even for late-joins is to set the currently held item variable as a replicated variable with a callback every time it changes. When it changes to a non-null variable, it plays various pickup fx such as particles or transform parent properties.

    For drops, we've found the best way is to just call a drop RPC function on the item that detaches from the character and turns on physics, etc. You can't rely on the previous replicated variable with a callback, because if it's null it doesn't know how to reset the state of the item. Only the item would know.
     
    tinyant and jesusluvsyooh like this.
  4. michaelgulak

    michaelgulak

    Joined:
    Oct 19, 2019
    Posts:
    4
    Thank you for the insight e_Zinc. This was very helpful for a project I'm working on.