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
1
Question by Duality · Jun 28, 2013 at 02:29 PM · terrainsplatmaps

Changes made to terrain alpha maps are persistant.

Hi!

When I make changes to the terrains textures during runtime by changing the alphamaps, the changes are permanently saved onto the terrain (in the scene, not(!) only during runtime). I can't image that this is supposed to work this way, but anyway, whether it's a bug or a "feature", is there a way that changes made to the terrains textures are reverted at the end of runtime?

Thanks in advance for any help!

EDIT:

Here's the code, which simply retrieves the alphamap for a specific position and re-weights the first texture to 100%. The Flush in the end doesn't seem to do anything, maybe deprecated!?

         Terrain terrain = GameObject.Find("Terrain").GetComponent<Terrain>();
         TerrainData terrainData = terrain.terrainData;
         Vector3 terrainPos = terrain.transform.position;
 
         // calculate which splat map cell the worldPos falls within (ignoring y)
         int mapX = (int)(((worldPos.x - terrainPos.x) / terrainData.size.x) * terrainData.alphamapWidth);
         int mapZ = (int)(((worldPos.z - terrainPos.z) / terrainData.size.z) * terrainData.alphamapHeight);
 
         // get the splat data for this cell as a 1x1xN 3d array (where N = number of textures)
         float[, ,] splatmapData = terrainData.GetAlphamaps(mapX, mapZ, 1, 1);
 
         splatmapData[0, 0, 0] = 1;
         splatmapData[0, 0, 1] = 0;
         splatmapData[0, 0, 2] = 0;
         splatmapData[0, 0, 3] = 0;
 
         terrainData.SetAlphamaps(mapX, mapZ, splatmapData);
         terrain.Flush();
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
0

Answer by Kirbyrawr · Jun 28, 2013 at 05:23 PM

You can do a script for putting the same textures in the terrain when you press stop.

Comment
Add comment · Show 4 · 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 Duality · Jun 29, 2013 at 06:05 AM 0
Share

I thought about this for a quick workaround as well, but it's not really a long term solution. If the user forces the game to quit abruptly, or it crashes, the script won't be executed.

avatar image SinisterRainbow · Jun 29, 2013 at 08:18 AM 0
Share

I don't know for sure, but i haven't seen any docs on it, and tho it can suck it doesn't necessarily surprise me. I thought you were doing this another way (decals). There are other solutions, one save all original data and restore at game start (probably easiest way), or don't mess with the terrain, use decals. (CryEngine for example projects decals onto an area, relatively expensive (adds a few draw calls) but can be removed anytime, and essentially what you are trying to do i believe). If that's not possible in unity, i know you could generate a mesh from the part of the ground affected and slap a texture on it. This would be deleted for certain at game start and is more flexible (i.e. you can remove it during runtime if ever necessary)

avatar image Duality · Jun 30, 2013 at 06:37 AM 0
Share

Interesting ideas. Having a duplicate of the data is how I would except it to work. The terrain SHOULD create a temporary copy at game start which is used and edited during runtime, and simply overwritten by the original data on the next game start. Doing this manually should work, but still feels like a huge hack. Wondering if they are planning to do something about that.

avatar image SinisterRainbow · Jun 30, 2013 at 07:21 AM 0
Share

It'd be nice, I'd like to know as well for certain. I haven't been using unity more than a couple of months, I notice this before for something that didn't restore, but i couldn't say what atm.

You may want to opt for the decal system, I was messing with GL stuff today and you can project textures this way relatively cheaply (as in, a single draw call kind of cheap), and onto more than just terrain surfaces. GL is quite easy for this, and may be a good solution for what you need.

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

Modifying terrain texture not updating 1 Answer

Terrain in an RTS style game 1 Answer

Why is directional light screwing up my textures? 2 Answers

Generate Alpha Map Procedurally... 1 Answer

Get Terrain material / Set splat maps 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