How can I revert a section of terrain?

I’ve made a placement system for placing shelters down on terrain. Currently when you place a shelter down it makes flat terrain underneath it by filling in a part with terrain. Issues happen when you remove your shelter - the land underneath is still flat. How would I make it so when you remove your shelter the terrain underneath it reverts to what it was before you placed your shelter?

1 Like

I would go about it like this:

  1. When you place a shelter, use CopyRegion to make a copy of the chunk of terrain underneath the shelter. Store the TerrainRegion you get somewhere with the data for the shelter.
  2. When you remove the shelter, use PasteRegion to revert the change.

Things get more complicated if:

  • Two shelters can have overlapping flat regions.

    • In the case where shelter B’s flat region intersections shelter A’s, you’ll need to revert the terrain under A before calling CopyRegion on B’s terrain, then you can flatten both again.
  • You need to store the TerrainRegion in a DataStore

    • This is probably fine, but I’m not 100% sure that TerrainRegions can be stored in DataStores. If they can’t, you would need to implement your own version of CopyRegion/PasteRegion using ReadVoxels/WriteVoxels.
2 Likes

Thanks for your reply! The game has a feature where you cant overlap each others shelters! When you place your shelter down a 28 studs area around the shelter is also yours!

Makes your life easier then :slight_smile:

1 Like