Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only.

    Please, do not make any changes to your username or email addresses at id.unity.com during this transition time.

    It's still possible to reply to existing private message conversations during the migration, but any new replies you post will be missing after the main migration is complete. We'll do our best to migrate these messages in a follow-up step.

    On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live.


    Read our full announcement for more information and let us know if you have any questions.

Using TerrainPaintUtility in game works in preview but not build

Discussion in 'World Building' started by qgi, Jul 30, 2019.

  1. qgi

    qgi

    Joined:
    Feb 12, 2007
    Posts:
    8
    I'm experimenting with modifying terrain in-game with TerrainPaintUtility in the Experimental.TerrainAPI.

    Basically I'm calling TerrainPaintUtility.BeginPaintHeightmap, blit the modification into the paintContext's destinationRenderTexture and then call TerrainPaintUtility.EndPaintHeightmap.

    This works great in preview mode but doesn't work in an actual build.
    I've tried calling SyncHeightmap on the corresponding terrainData afterwards but that didn't do the trick.

    What additional steps are required to get this working in the game build, or are these methods only intended for use in the editor?

    Thanks!
     
  2. ChrisTchou

    ChrisTchou

    Unity Technologies

    Joined:
    Apr 26, 2017
    Posts:
    74
    I just tested it on 2018.4LTS, and it appears to work in a PC standalone build.
    What version of Unity / what platform are you using?

    Possibly there is a bug where it is not including the new height copy shader in recent 2019.3 builds (newly added to fix some other issues).

    In 2019.3, you can probably workaround it by grabbing the built-in shaders for your version of Unity here:
    https://unity3d.com/get-unity/download/archive

    And copying
    DefaultResourcesExtra\TerrainShaders\Utils\TerrainHeightBlitCopy.shader

    into a Resources\ directory in your project.
     
    wyattt_ likes this.
  3. qgi

    qgi

    Joined:
    Feb 12, 2007
    Posts:
    8
    Chris, Thank you for your answer. I've been trying with 2019.1.11 and 2019.1.12 on macOS. In both versions it works in game preview but not in the standalone build. I've converted the project to 2019.3.0a10 but that didn't help either.
    The Builtin Shaders package for 2019.3.0a10 doesn't contain a TerrainHeightBlitCopy.shader (neither do the packages for 2019.1.11/12) so I couldn't try what you suggested.
    I've also tried with 2018.4.5f1. That doesn't seem to work either.
     
  4. GamesEngineer

    GamesEngineer

    Joined:
    Aug 22, 2014
    Posts:
    9
    I'm having this issue, too. I'm using Unity 2018.4.25f1 (LTS). The TerrainPaintUtility works in the editor's game preview, but in a standalone build (Windows 10) the call to TerrainPaintUtility.GetBuiltinPaintMaterial() returns null. I presume that's because the shader is that Chris mentioned is stripped from the build. But I'm unable to find it in order to add it to the project's preloaded assets list.

    UPDATE: I found the correct shaders. To be more clear about where to get these shaders: go to the Unity Download Archive web page, find your version of Unity and change the drop-down selector from "Downloads (WIN)" to "Built in shaders". Inside the ZIP file that is downloaded there is a folder named "DefaultResourcesExtra\TerrainShaders\Utils". I copied those shaders into a "Resources" folder in my Unity project. Then after rebuilding the standalone game, everything works as intended.
     
    Last edited: Aug 7, 2020
    wyattt_ and Lesnikus5 like this.