Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 J0rdy · Sep 09, 2015 at 07:08 PM · terraintexturesterraintextureterrainpainting

How to change textures on terrain?

Hi. I'm quite new in Unity3D. In my game an user can have his own city . At some moment in the game all the sand roads in the game for example should be replaced by stone roads. Or at a certain moment texture x should be overwritten with texture y at some places on my terrain. So not everywhere.

What is the best way to achieve that? Like a toggle function within specific coordinates or...

Thank you very much!

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 Ambrose998800 · Sep 09, 2015 at 11:13 PM

You could use a material change script.

 private var MatStone: Material;
 private var MatConcrete: Material;


 function Start(){

 MatStone= Resources.Load("Material/Stone", Material);
 MatConcrete= Resources.Load("Material/Concrete", Material);

 }
 
 function "changeMat"(){
 
 if (RoadObject.GetComponent("RoadScript").MatName == "Stone"){
            RoadObject.GetComponent(Renderer).material = MatStone;
 }
 if (RoadObject.GetComponent("RoadScript").MatName == "Concrete"){
         RoadObject.GetComponent(Renderer).material = MatConcrete;
 }

 }
Comment
Add comment · Show 3 · 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 J0rdy · Sep 10, 2015 at 07:38 PM 0
Share

Thank you! But how to do it for specific places on the terrain, and not for the complete terrain?

avatar image Suddoha · Sep 10, 2015 at 07:47 PM 0
Share

With this apporach you cannot, it's always gonna change the complete texture. Every texture added to the terrain's texture list is basically applied to the whole terrain. The only control of local appearence is an alpha value. You cannot partially replace a terrain texture in Unity unless you create your own terrain system. Have a look at my answer, this way it's possible to "replace" a texture while keeping it at some places, but you won't actually replace it, you'll just manipulate the alpha value.

avatar image Ambrose998800 · Sep 11, 2015 at 07:40 AM 0
Share

In case of terrains - and if you want to use the material change; i would build them (for example) with Blender, that supports Unity material specification within. There are smooth blendover in materials on meshes too by brushing.

Unfortunately, Unity has just a crappy terrain tool. You can't even build caves. With Blender you can. If you want use the grass paint tool from Unity on an extern terrain too, just make a underlayed Unity-terrain to your imported one.

avatar image
0

Answer by Suddoha · Sep 10, 2015 at 12:46 AM

That's actually not too difficult. The only thing that you really have to find out by yourself is which algorithm you want to use to determine which areas should be changed.

As for the change of texture, you're probably looking for TerrainData.GetAlphamaps. Basically, the terrain is organized in different layers for the textures. Every texture that you add to the terrain's texture list can be thought of as "applied to the complete terrain". When "drawing" a texture on the terrain, the engine manipulates values at those positions for the specific texture which represent an alpha value.

Example: Texture 1: Sand, Texture 2: Stone, Texture 3 Gras.

If you want to add some gras (without opacity, i.e. you only see the gras texture, no blend effect), the respective alpha values at the position will be set to 0 for the sand and stone, 1 one for the gras. Note, that the values should be clamped to a maximum of 1 in total, higher values will result in annoying (often bright) effects.

*EDIT

Important sidenote: Any changes done by scripts during playmode will not be reverted. You have to make your own copy, either via script or manually, before you start your experiments.

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 jayjf · Sep 10, 2015 at 07:25 AM 1
Share

That would be the best way. Here is a tutorialwith some sample code that I found some time ago. As said, the algorithm how to deter$$anonymous$$e what the values are for a position is something that you have to figure out for your setup.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Terrain look 1 Answer

Why do programmatically generated textures behave differently than manually added textures when used as Terrain splats? 0 Answers

Can't find the paint / raise / lower terrain setting in unity 2018.3 1 Answer

TriPlanar Textures Not Working Properly 1 Answer

My terrain textures are still horrible!! 3 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