Search Unity

TerraVol Multiplayer Editing

Discussion in 'Scripting' started by Connor_13_, Jul 1, 2014.

  1. Connor_13_

    Connor_13_

    Joined:
    Mar 14, 2014
    Posts:
    40
    I am working on a multiplayer game and I am trying to implement real time editing of terrain using the asset TerraVol. I successfully made the terrain generate the same for all players on the network with the help of Network.Instantiate.

    The first issue I have run into is that I cannot locally edit terrain that was instantiated using Network.Instantiate. I can, however, edit terrain locally if I click and drag the map object into the scene from the file viewer. I assume this happens because the terrain was instantiated on the network rather than just a normal local instantiate. When I try to edit the terrain that was instantiated using Network.Instantiate i get this error...

    NullReferenceException: Object reference not set to an instance of an object
    TerraVol.ActionData..ctor (Vector3i position, Vector3 size, TerraVol.Block blockType, ActionDataType type, BrushType brush, Single isovalueToAdd, Boolean createVegetation, Boolean force) (at Assets/TerraVolPack/TerraVol/Scripts/Data/ActionData.cs:148)
    Builder.DoAction (Nullable`1 point) (at Assets/TerraVolPack/TerraVol/Scripts_to_customize/Builder.cs:251)
    Builder.Update () (at Assets/TerraVolPack/TerraVol/Scripts_to_customize/Builder.cs:91)

    I dont get that error when the terrain is instantiated locally.

    I am very confused.. hopefully someone who knows something about TerraVol can help me out.

    Thanks
     
  2. Connor_13_

    Connor_13_

    Joined:
    Mar 14, 2014
    Posts:
    40
    Fix: Oddly enough, the order in which the objects were instantiated mattered.
     
  3. CyberKot93

    CyberKot93

    Joined:
    Jul 6, 2014
    Posts:
    7
    I don't use TerraVol, but think, that you can use Network.RPC call to your server, and modify terrain on it. And server will sent data to other connected players.
     
  4. Connor_13_

    Connor_13_

    Joined:
    Mar 14, 2014
    Posts:
    40
    Yep thats what I did
     
  5. PvTGreg

    PvTGreg

    Joined:
    Jan 29, 2014
    Posts:
    365
    how did you manage to make the terrain generate for more than one player? i cant figure out how
     
  6. Connor_13_

    Connor_13_

    Joined:
    Mar 14, 2014
    Posts:
    40
    I made the server generate the terrain and then save the .terra file to the network by turning it into a byte array and using RPC calls to send and deserialize it.

    For the saving and sending of the .terra file I edited the Builder.cs class. On the clients, in the TerraMap class, I tested to see if the instance was client or server. If it was client, I set the loadPath to the path where the file would end up once deserialized. I did that test because I used Network.Instantiate on the Map gameobject.

    Hopefully that helps a little bit.
     
  7. PvTGreg

    PvTGreg

    Joined:
    Jan 29, 2014
    Posts:
    365
    think that just confused me more
    how do you handle players in differant chunks?