Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question How to quickly change the height of the terrain?

Discussion in 'Editor & General Support' started by Zimaell, Aug 5, 2023.

  1. Zimaell

    Zimaell

    Joined:
    May 7, 2020
    Posts:
    337
    I need to change the height of the terrain during the game, for example, as if the character is digging, I apply terrainData.SetHeights and it works, but it doesn’t matter how many points I change, at least 10 at least one processing time for such a request will be 0.3-0.4sec (well, I have so at least), of course, this is a lot, since if this happens often in the game, it will cause friezes, in general, the question is - how to adjust the height of the terrain faster?

    I must say right away that the advice on reducing the resolution is out of place, since at the moment I have a 1000x1000 terrain and it costs 513x513, in general, so little, but here are the results.

    And of course, I thought about dividing the terrain not a few, in my case by 100 by 100, but then how to smooth out the transitions of textures and meshes between them?
     
  2. Lurking-Ninja

    Lurking-Ninja

    Joined:
    Jan 20, 2015
    Posts:
    9,900
    In a nutshell? You don't. Unity's current terrain is old and wasn't made for this. It was made for editing in editor on editor time once and just load the moderate sized terrain into the game. Nothing else really.

    You should replace the terrain with custom mesh and write your own mesh-modifying algorithms. Or find some library that does that. But Unity terrain isn't really a fast thing.
    Although if you turn off physics for it, that may help, but then you will end up without collision and whatnot.
     
    Zimaell and Kurt-Dekker like this.
  3. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,557
    In general, making a terrain modifying game is a Very Hard Thing(tm). You will be required to reason about all steps of the data cascade from the user input to the original authored terrain to the final output. Every part of that will need to operate at a suitable scale.

    As Lurk points out, to do any meaningful solution will likely require your own custom terrain system, specifically tailored to your specific game needs.

    Here are some of my terrain fiddlings with Unity, source linked in each video's comments:





     
    Zimaell likes this.
  4. Zimaell

    Zimaell

    Joined:
    May 7, 2020
    Posts:
    337
    I don’t need terrain physics, I have NPCs moving along the verticles of the terrain,

    Kurt-Dekker thanks for the examples.

    I haven’t reviewed all the examples yet, but I’m already thinking whether to switch to my own mesh, I mean create my own terrain, it seems to me that it will be more expensive, even without physics, you need to think over the UV maps, as well as the lod system and visibility like in a terrain.
     
  5. Lurking-Ninja

    Lurking-Ninja

    Joined:
    Jan 20, 2015
    Posts:
    9,900