Search Unity

Events Happening Before a Player Joins

Discussion in 'Multiplayer' started by HarryMcCaffery, Mar 19, 2018.

  1. HarryMcCaffery

    HarryMcCaffery

    Joined:
    Oct 16, 2016
    Posts:
    14
    Hi everyone-

    My problem is something pretty straightforward that I have been trying to solve for some time, so hopefully you guys will be able to help.

    Basically, the chain of events goes like this:

    A player places/modifies and object

    A Server command/rpc is executed to place the object and set its properties (ex parent, color)

    A while later, the second player joins

    I know I can use syncvar for numbers and such, but how do I sync properties such as transforms?

    Right now the player can join and see the object, and it functions correctly except for properties such as a the parent.

    Thanks, I hope I was clear enough and I would be happy to elaborate.

    -Harry
     
  2. HarryMcCaffery

    HarryMcCaffery

    Joined:
    Oct 16, 2016
    Posts:
    14
    In short what I am looking for is a way to sync variables incompatible with syncvars without using an array, as the array would always be changing. I have googled this over and over and have yet to find a solution.
     
  3. HarryMcCaffery

    HarryMcCaffery

    Joined:
    Oct 16, 2016
    Posts:
    14
    Another example of my problem- When an explosion occurs and creates a crater in the terrain, and another player joins after the explosion, there is no crater. If there were to be a way to execute all the explosions that had ever occurred when a new client joins, this would create all the craters, but I still do not understand how this is to be done other than creating an array with lots of numbers describing all of the explosions.

    Thanks,
    -Harry
     
  4. HarryMcCaffery

    HarryMcCaffery

    Joined:
    Oct 16, 2016
    Posts:
    14
    The terrain example is probably the most clear example that I can give- and understanding the solution to this problem would solve one of the final roadblocks In creating my game.
     
  5. HarryMcCaffery

    HarryMcCaffery

    Joined:
    Oct 16, 2016
    Posts:
    14
  6. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    If these are things you're already setting with a ClientRpc, you could send a TargetRpc to the newly joined player with the same information.
     
  7. HarryMcCaffery

    HarryMcCaffery

    Joined:
    Oct 16, 2016
    Posts:
    14
    Awesome! I appreciate the help, this solves the first half of the problem.

    So there is no easier way to approach the explosion problem other than storing an array of numbers and then sending it to the new player?

    Thanks,
    -Harry

    EDIT: A buffered rpc is what they call this with photon, is there a built-in unity equivalent?
     
  8. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    There is no built in equivalent to buffered RPCs in UNET. Because of this I usually favor SyncVars or SyncLists for things I need to exist in newly connected clients, and favor RPCs for things that are immediate and temporary. Your exploded craters for example could be a SyncList of Vector3's or a SyncListStruct, which would automatically populate for any newly connecting player.

    You could also consider writing your own RPC buffer system to use with specific RPCs you need to buffer. Store all your explosion locations in a list, and then send target RPC's to newly connecting clients either with the list or a series of target RPC's.
     
    Last edited: Mar 21, 2018
  9. HarryMcCaffery

    HarryMcCaffery

    Joined:
    Oct 16, 2016
    Posts:
    14
    I supposed writing my own system wouldnt be too hard- just store all the variables I need in a synclist and then make sure the client executes the proper code on join. I guess I just need to rethink how I’ll approach a few things.


    Thanks again for the help- I really appreciate it. I rarely go to the forums for help as google is usually enough! Haha making single player games is so much less a headache than multiplayer-