Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Multiplayer trees

Discussion in 'Multiplayer' started by malkere, Dec 22, 2018.

  1. malkere

    malkere

    Joined:
    Dec 6, 2013
    Posts:
    1,212
    Ore, rocks, monsters etc. I just Spawn() and that's fine. Trees need to be batched on the terrain though or they really impact performance. I don't really want to use a proximity checker because it will call flush on my terrains quite often as the player moves around.

    My game already spawns tree colliders manually for tree harvesting using the locations of the treeInstances.

    My first approach was to just use the same seed for generation and to look for colliders marked as "dead" and turn those trees graphics off client side.

    In my new approach I don't spawn any tree graphics on the client until the colliders are spawned; there are in general 2 scenarios:
    1. The player joins the server and an area that is already loaded where the tree colliders are already spawned. Once the client terrain generates it ScanForTrees() and gathers all the tree colliders within its bounds, spawning any TreeInstances that are not marked as dead.
    2. While moving around the player ends up generating a terrain faster than the server and scans for zero trees. Afterwards the tree colliders are Spawn()'d and show up on the client. In the OnStartClient() they call the terrain for a rescan. The terrain then ScanForTrees() again and this time picks up the trees, rendering their graphics.

    I was curious how others have approached this problem?
     
  2. voncarp

    voncarp

    Joined:
    Jan 3, 2012
    Posts:
    187
    LOD and GPU instancing. Check CullingGroupEvent hasBecomeVisible to render the tree. Then spawn in colliders for LOD 0. This way you would only need to spawn in a handful of colliders for the closest trees. And only for the trees that are visible.
     
    malkere likes this.
  3. malkere

    malkere

    Joined:
    Dec 6, 2013
    Posts:
    1,212
    LOD does help with collider management, and that's an approach to it I hadn't heard of, thank you for that. But I can't only spawn the nearest trees for the client or that would be a big change in scenery. Even on low settings trees are usually rendering billboards 500-1000m+. The real problem is getting all of that sync'd across the network. The only two ways I've come up with are to either send the all the information necessary to replicate the scene, or generate with a seed based method and update only any changes to the base results.

    If I knew how to manually batch SpeedTrees and what not at least as effectively as Unity Terrains do then I wouldn't have to flush() and could just use proximity checker updates.... o_O
     
  4. malkere

    malkere

    Joined:
    Dec 6, 2013
    Posts:
    1,212
    I missed your reply somehow @voncarp Getting back into playing around with my own custom vegetation this weekend. Thanks for the tips!