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
3
Question by Logopolis · Mar 02, 2015 at 06:21 PM · terrainterraindatasplatsplatmaps

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

I have a terrain prefab. If I place more than one instance of this terrain in my scene (either using the editor or using a script) and then paint textures onto one of them (modifying the splat map), the same changes to the splat map appear on the other instance as well. See the picture below -- I painted the green 'S' on one instance of the landscape, and it appeared on both. How can I make these instances completely separate so that I can modify their splat maps separately?

Note that I already tried giving them different TerrainDatas, by script. That allowed me to change their height maps separately, but not their splat maps.

Painted on one, the change appeared on both

unity-question1.jpg (60.3 kB)
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
2

Answer by einWikinger · Oct 28, 2015 at 09:46 AM

I just wrote a complete deep-copying helper as I had to duplicate a source terrain into distinct copies:

https://gist.github.com/zsoi/c965ff38938cd126f00d

This way copying a terrain is as easy as:

newTerrain.terrainData = ZS.Tools.TerrainDataCloner.Clone(sourceTerrain.terrainData);

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 Eldoir · Aug 16, 2017 at 10:26 AM 0
Share

Thanks for this @einWikinger. Just fixed a bug in your script about treePrototypes and it's all good. $$anonymous$$ade my day!

avatar image
1

Answer by Logopolis · Mar 03, 2015 at 12:31 AM

In case anyone else has this problem in the future, here's the solution I found. First, I instantiated the terrain:

 terrainPatches[x,z] = (Terrain) Instantiate(terrainPrefab, new Vector3(0, 0, 0), Quaternion.identity);

Then, I needed to create a new TerrainData instance from scratch. It didn't work if I instantiated the TerrainData instance from a prefab -- they would all share the same splat maps. Instead, I had to create each TerrainData from scratch, fill in its attributes, and create the array of SplatPrototypes for each one. Here's the code I'm using, that solved the problem:

 terrainPatches[x,z].terrainData = new TerrainData();
                 terrainPatches[x,z].terrainData.heightmapResolution = 129;
                 terrainPatches[x,z].terrainData.size = new Vector3(200,80,200);
                 terrainPatches[x,z].terrainData.alphamapResolution = 128;
                 terrainPatches[x,z].terrainData.baseMapResolution = 256;
                 terrainPatches[x,z].terrainData.SetDetailResolution(256, 8);
                 SplatPrototype[] splatPrototypes = new SplatPrototype[10];
                 for (int i = 0; i < 10; i++) {
                     splatPrototypes[i] = new SplatPrototype();
                     splatPrototypes[i].tileOffset = new Vector2(0,0);
                     splatPrototypes[i].tileSize = new Vector2(20,20);
                     switch (i) {
                     case 0: splatPrototypes[i].texture = terrainTexture0; splatPrototypes[i].normalMap = rockNormalMap; break;
                     case 1: splatPrototypes[i].texture = terrainTexture1; break;
                     case 2: splatPrototypes[i].texture = terrainTexture2; break;
                     case 3: splatPrototypes[i].texture = terrainTexture3; splatPrototypes[i].normalMap = grassNormalMap; break;
                     case 4: splatPrototypes[i].texture = terrainTexture4; splatPrototypes[i].normalMap = rockNormalMap; break;
                     case 5: splatPrototypes[i].texture = terrainTexture5; splatPrototypes[i].normalMap = rockNormalMap; break;
                     case 6: splatPrototypes[i].texture = terrainTexture6; break;
                     case 7: splatPrototypes[i].texture = terrainTexture7; break;
                     case 8: splatPrototypes[i].texture = terrainTexture8; break;
                     case 9: splatPrototypes[i].texture = terrainTexture9; break;
                     }
                 }
                 terrainPatches[x,z].terrainData.splatPrototypes = splatPrototypes;

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.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Unity Terrain Texture Swap...how to? 3 Answers

Different renders of Terrain Splat Protypes in Real Time 1 Answer

Deleting terrain splatmap through scripts. 1 Answer

heightmapWidth and heightmapHeight always equal 1 Answer

Modifying terrain texture not updating 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