Search Unity

Differenciate between spawning before or after a player joins

Discussion in 'Multiplayer' started by Gaucho, Sep 15, 2020.

  1. Gaucho

    Gaucho

    Joined:
    Apr 21, 2013
    Posts:
    12
    My game is spawning numerous items during runtime on some player actions. Every time, a prefab is being spawned by using `NetworkServer.Spawn(element)`, it is being animated and plays a sound to make it feel more alive. Lets assume, Player 1 spawns 20 Items, then Player 2 joins, then they'll spawn 10 more.

    How can i identify if an GameObject gets spawned after i joined or if it was already spawned (and only synced) before i joined?
     
  2. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    You could set and sync a timestamp on each networked object. If the synced timestamp is older than the timestamp on your player object, then the object was spawned before the player joined, otherwise it spawned after the player joined.