• 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 AaronC · May 29, 2010 at 03:44 AM · terrainmaskterraindataswapsplatmaps

Unity Terrain Texture Swap...how to?

Hi 3 scenarios:

  1. I have one texture, a map covering whole terrain-no tiling. Can I by script swap that entire texture for another also with no tiling? How would I do that?

  2. say I am using 3 or four splatmaps, can I swap one of these out for another texture at runtime also? so ingame I can swap out grass for dirt for example?

  3. can you use a greyscale mask to define where certain splatmaps are painted?

Many thanks AC

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by dex · May 30, 2012 at 06:17 PM

I am currently using the following function, but it does not seem efficient enough, so i am also looking for a better solution.

 // Load specified texture and only that texture in given terrain
 void LoadTerrain(TerrainData terrain_data, int texture_level) {

     float[, ,] alphas = terrain_data.GetAlphamaps(0, 0, terrain_data.alphamapWidth, terrain_data.alphamapHeight);

     // make sure every grid on the terrain is modified
     for (int i = 0; i < terrain_data.alphamapWidth; i++) {
         for (int j = 0; j < terrain_data.alphamapHeight; j++) {

             // make sure only set layer is visible
             for (int k = 0; k < terrain_data.alphamapLayers; k++) {
                 if (k == texture_level) {
                     alphas[i, j, k] = 1;
                 } else {
                     alphas[i, j, k] = 0;
                 }
             }
         }
     }

     // apply the new alpha
     terrain_data.SetAlphamaps(0, 0, alphas);
 }
Comment
Add comment · Show 1 · 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
0

Answer by ScroodgeM · Jul 19, 2012 at 06:11 PM

http://answers.unity3d.com/questions/285816/change-terrain-texture-and-tree-at-runtime.html#answer-285924

a little upgraded script that allows to change texture without full repainting, e.g. it saves paint map and changes texture.

Comment
Add comment · 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

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

How can I get two different terrain instances to use different splat maps? 2 Answers

Procedural terrain generation based on color mask 0 Answers

Terrain and PerlinNoise Glitch 0 Answers

Why do smaller terrains have higher triangle count? 0 Answers

terrain の detail について (About Terrain Detail),terrain の detail について (About Terrain Detail) 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges