• 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
Question by x70x · Sep 24, 2014 at 05:17 PM · instantiateterrainprefabeditor-scriptingterraindata

Editing Terrain prefabs directly from a custom editor window. Updates not applying to scene instances.

I am using a custom editor window to automate changes to a 4x4 grid of terrain prefabs. The problem is that some Terrain variable changes do not seem to propagate out to scene instances immediately.

alt text

For example, here you can see that when I select the prefab in the project folder the pixel error value has been set to 5 via my editor window, but below that is an image showing that the prefab instance in the scene still has the old value of 2 for the pixel error.

alt text

However, after entering play mode once the values then seem to update properly in the inspector (and reflect those changes in the scene view as well). Is there a way to force this update via code rather than needing to enter play mode?

I get the reference to my terrain GameObject prefab in the project folder using the AssetDatabase.LoadAssetAtPath method and call the following function on that prefab:

 void ApplyTerrainSettings(GameObject terrainGo) {
 
         //Terrain Settings
         basemapDistance = 1000;
         castShadows = true;
         detailObjectDensity = 1.0f;
         detailObjectDistance = 70;
         heightmapPixelError = 5;
         
         //Terrain Data Settings
         terrainWidth = 2000;
         terrainLength = 2000;
         terrainHeight = 4250; //Combine for terrainData.size Vector3
         heightmapResolution = 2049; //Heightmap Resolution
         detailResolution = 1024; //Detail Splatmap Resolution
         detailResolutionPerPatch = 16; //Detail Splatmap Resolution Per Patch
         alphamapResolution = 2048; //Control Texture Resolution
         baseMapResolution = 1024; //Base Texture Resolution
 
         Terrain terrainComp = terrainGo.GetComponent<Terrain>() as Terrain;
 
         terrainComp.basemapDistance = basemapDistance;
         terrainComp.castShadows = castShadows;
         terrainComp.detailObjectDensity = detailObjectDensity;
         terrainComp.detailObjectDistance = detailObjectDistance;
         terrainComp.heightmapPixelError = heightmapPixelError;
 
         terrainComp.terrainData.size = new Vector3(terrainWidth, terrainHeight, terrainLength);
         terrainComp.terrainData.heightmapResolution = heightmapResolution;
         terrainComp.terrainData.SetDetailResolution(detailResolution, detailResolutionPerPatch);
         terrainComp.terrainData.alphamapResolution = alphamapResolution;
         terrainComp.terrainData.baseMapResolution = baseMapResolution;
 
         terrainComp.Flush();
 
         EditorUtility.SetDirty(terrainGo);
     }




pixelerror5.png (35.5 kB)
pixelerror2.png (36.3 kB)
Comment

People who like this

0 Show 0
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

0 Replies

· Add your reply
  • Sort: 

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

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

2 People are following this question.

avatar image avatar image

Related Questions

Editor Script: Linking GameObjects to public script variables resets when playing. 1 Answer

Terrain: Use as scenario (individual) and prefab (unchanged, reusable) 0 Answers

Instantiating multiple objects, Destroying and instantiating on trigger + delay 0 Answers

Instatiating an object. Altering that new object causes prefab to be altered. 2 Answers

Editor-Scripting: Change selected terrain layer 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