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
2
Question by karl_ · Jan 29, 2012 at 11:28 PM · terrainterraindataduplicateunique

Making Duplicate Terrain Unique?

I need the ability to make a duplicate terrain unique, so that I may edit it's terrainData without affecting the original terrain. I found this question http://answers.unity3d.com/questions/58342/problem-with-terrain-duplicates-simple.html that seems to indicate the only way is to reimport the heightmap, but that does not account for the trees and texture data. I've tried manually copying the terrainData info and reapplying it to a new terrain, but that still connects the data to the original.

Here is my code thus far, which just connects the terrain with the old terrainData. Is there a way to make the copied terrainData unique from the old?

 using UnityEditor;
 using UnityEngine;
 
 public class TerrainTools : EditorWindow
 {
     [MenuItem("Tools/Terrain Tools")]
     static void Iinit(MenuCommand command)
     {
         TerrainTools i = (TerrainTools)ScriptableObject.CreateInstance(typeof(TerrainTools));
         i.ShowUtility();
     }
     
     void OnGUI()
     {
 
         Terrain ter = Terrain.activeTerrain;
         GUILayout.Label("Terriain Name: " + ter.name, EditorStyles.boldLabel);
         
         if(GUILayout.Button("Store Terrain Data"))
             StoreTerrainData();
         
         if(GUILayout.Button("Set Terrain Data"))
             SetTerrainData();
         
         if(GUILayout.Button("Reset Terrain Data"))
             ResetTerrain();
         
         GUILayout.Space(10);
         
         GUILayout.BeginHorizontal();
             GUILayout.Label("Currently Stored Data ", EditorStyles.boldLabel);
             GUILayout.Label(stored);
         GUILayout.EndHorizontal();
         
         GUILayout.BeginHorizontal();
             GUILayout.Label("Currently Selected ", EditorStyles.boldLabel);
             GUILayout.Label(Terrain.activeTerrain.terrainData.name);
         GUILayout.EndHorizontal();
     }
     
     void ResetTerrain()
     {
         Terrain.activeTerrain.terrainData = new TerrainData();
     }
     
     TerrainData terData = new TerrainData();
     string stored = "";
     void StoreTerrainData()
     {
         stored = Terrain.activeTerrain.terrainData.name;
         terData = Terrain.activeTerrain.terrainData;
     }
     
     void SetTerrainData()
     {
         if(terData != null)
         {
             Terrain.activeTerrain.terrainData = terData;    
         }
     }
 } 
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
3
Best Answer

Answer by Rabbit-Stew-dio · Feb 03, 2012 at 08:23 PM

You will need to clone your original TerrainData to separate the copy from the original.

 TerrainData newTerrainData = (TerrainData) Object.Instantiate(terData);

will do the trick. So your "Store" method should read:

 void StoreTerrainData()
 {
    stored = Terrain.activeTerrain.terrainData.name;
    terData = (TerrainData) Object.Instantiate(Terrain.activeTerrain.terrainData);
 }

One more trap to be aware of: Your game object that contains the terrain (Terrain.activeTerrain.gameObject) usually also has a TerrainCollider on it. When you update the terrain data, you should also update the terrain collider.

 void SetTerrainData()
 {
    if(terData != null)
    {
      TerrainData newTerrainData = (TerrainData) Object.Instantiate(terData);
      Terrain.activeTerrain.terrainData = newTerrainData; 
      TerrainCollider tc = Terrain.activeTerrain.gameObject.GetComponent<TerrainCollider>();
      tc.terrainData = newTerrainData;
    }
 }
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 I-am-Lawrence · Jan 30, 2016 at 02:40 AM 0
Share

Thanks for the answer. This definitely works, but as a warning there are strange happenin's in scene view after editing the copy's splat map. If you add the original terrain data to the scene, viewing it at different distances will alternate between the old splat map and the new splat map, so there is some data that is still being shared between the two somehow.

The problem seems to be resolved the next time the scene is saved... but it's still strange, and merits a bit of caution.

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

7 People are following this question.

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

Related Questions

heightmapWidth and heightmapHeight always equal 1 Answer

SetAlphaMaps Opacity Gradient 0 Answers

How do you make the material in the Terrain detail prototype properties update after runtime? 1 Answer

How to set Flatten HeightMap in Unity 4.2 1 Answer

SetPixel() on Terrain 0 Answers


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