Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by ForgeStudios · Sep 21, 2013 at 10:17 PM · c#terrainterrain gen

How to reset terrain alpha maps in runtime

The title explains it all, is there a way to reset a terrain's alpha map in runtime (reset the terrain 'paint')?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by clunk47 · Sep 22, 2013 at 12:01 AM

Look under variables and functions inside the Unity Script Reference for: TerrainData. You can tweak all of these via script, therefore at runtime :)

Comment
Add comment · Show 10 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ForgeStudios · Sep 22, 2013 at 12:18 AM 0
Share

I already looked over that, but it's quite ambiguous about terrain. When I tried to use alphamapSet it crashed my game.

avatar image syclamoth · Sep 23, 2013 at 02:02 AM 3
Share

I assume @ForgeStudios was referring to this.

avatar image clunk47 · Sep 23, 2013 at 03:10 AM 2
Share

The answer is in the link that @syclamoth gave you. http://docs.unity3d.com/Documentation/ScriptReference/TerrainData.SetAlphamaps.html

In your map variable, the last number should be the amount of layers, or textures you have painted on the terrain. To reset all paint to zero, here's an example of how to do this if you have a single paint layer, or texture.

 using UnityEngine;
 using System.Collections;
 
 public class Example : $$anonymous$$onoBehaviour
 {
     public Terrain t;
     float[,,] map;
     
     void Awake()
     {
         map = new float[t.terrainData.alphamapWidth, t.terrainData.alphamapHeight, 1];
         t.terrainData.SetAlphamaps(0, 0, map);
     }
 }

This is about the best constructive advice I can give.

avatar image ForgeStudios · Sep 23, 2013 at 03:24 AM 2
Share

Thanks! Based on what you said I did a bit of tweaking and got it working!

     void RunGen_Clear(){
         float[,,] map = new float[terrain.terrainData.alphamapWidth, terrain.terrainData.alphamapHeight, 25];
         for (int y = 0; y < terrain.terrainData.alphamapHeight; y++) {
             for (int x = 0; x < terrain.terrainData.alphamapWidth; x++) {
                 map[x, y, 0] = 1;
             }
         }
         terrain.terrainData.SetAlphamaps(0, 0, map);
     }
avatar image clunk47 · Sep 23, 2013 at 03:32 AM 1
Share

Glad that I as well as @syclamoth were able to sort this out for you. Any comments / answers that helped you resolve your concern definitely deserve a thumbs up. +1 for posting your solution. Happy Developing :)

Show more comments

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

17 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Distribute terrain in zones 3 Answers

perlin noise terrain is spikey 0 Answers

Multiple Cars not working 1 Answer

Instantiated Objects not Following Perlin Noise 0 Answers

Scaling and rotaion of terrain trees 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges