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

Is it possible to get Terrain heights as a 1D (blittable) array?

Discussion in 'World Building' started by VitruvianStickFigure, Jun 2, 2022.

  1. VitruvianStickFigure

    VitruvianStickFigure

    Joined:
    Jun 28, 2017
    Posts:
    38
    Pretty much just like the title—I can see that GetHeights returns a 2D array of floats, which is great for human presentation; unfortunately it does very little for the new Jobs System/ECS/Burst/etc. where blittable types are king.

    I have been simply flattening the 2D array to a 1D array, passing that, and then fattening it back up to a 2D array in the very end before setting heights to the new values. (There's a lot of procedural generation going on in this game, and the new systems should make it much more manageable.) However, I would be very surprised if, under the hood, Terrain does not already work with a 1D array—in the reference C# source code, it even calls an internal function under the hood, which seems to make it even more likely that it's sticking with native 1D.

    Not that I can prove any of that, it's just how I would do it.

    So in short, I feel like the flatten/fatten operations are likely redundant ones, and would like to know if some kind of established GetHeights1D-style method already exists. If I'm right about the under-the-hood 1D array, it would be great if someone would implement one!

    Thanks.