Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 /
  • Help Room /
This question was closed Jul 17, 2016 at 09:22 PM by Knarhoi for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by Knarhoi · Jul 17, 2016 at 07:31 PM · grassterraindatadetail

How do I edit the terrainData.detailPrototype.healthyColor at runtime?

Hello everyone!

I'd like the player to be able to modify the color of a furry carpet, using a GUI slider. So far the player can change the material.color of textures, but when it comes to grass, it seems less straight forward. I've read different posts...

  1. Assigning the color directly, as in my code, doesn't work.

  2. TerrainData.RefreshPrototypes doesn't help.

  3. And SetDetailLayer, as from the link below, seems to be about editing the number of details?

http://answers.unity3d.com/answers/13398/view.html

And the following link doesn't explain terrain in detail:

http://answers.unity3d.com/questions/13854/edit-terrain-foliagetexture-at-runtime.html

Here's my code:

     private DetailPrototype _detailPrototype;
 
     void Start()
     {
         _detailPrototype = _terrain.terrainData.detailPrototypes[0];
     }
 
     void Update()
     {
         _detailPrototype.healthyColor = Color.HSVToRGB(cSliderValueCarpet / 255f, hSliderValueCarpet / 255f, 1f);
     }















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

  • Sort: 
avatar image
2
Best Answer

Answer by Knarhoi · Jul 17, 2016 at 09:02 PM

I found the solution!

http://forum.unity3d.com/threads/swapping-terrain-prefabs-and-textures-during-runtime-through-scripts.92290/

Basically you have to assign to the prototype array itself and not to the individual prototypes.

     private DetailPrototype[] _detailPrototypes;
     
     void Start()
     {
         _detailPrototypes = _terrain.terrainData.detailPrototypes;
     }
 
     void Update()
     {
         _detailPrototypes[0].healthyColor = Color.HSVToRGB(cSliderValueCarpet / 255f, hSliderValueCarpet / 255f, 1f);

         _terrain.terrainData.detailPrototypes = _detailPrototypes;
     }


Comment
Add comment · Show 2 · 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 jubaerjams8548 · Sep 05, 2021 at 08:27 AM 0
Share

What about this one? , Grass color is not getting chnaged...what to do??

public class Grass_Color_Changer : MonoBehaviour { public Color Grass_Color;

 TerrainData terrainData;

 public void Start()
 {
     terrainData = GetComponent<Terrain>().terrainData;
 }
 void Update()
 {
     if (Input.GetKeyDown(KeyCode.M))
     {
         terrainData.detailPrototypes[0].dryColor = Color.HSVToRGB(255f, 255f, 1f);
         terrainData.detailPrototypes[0].healthyColor = Color.HSVToRGB(255f, 225f, 1f);
         Debug.Log("Working");
     }

}

avatar image Knarhoi jubaerjams8548 · Sep 05, 2021 at 12:01 PM 0
Share

It looks like you're providing the same color (255f, 255f, 1f) as both dryColor and healthyColor. So you won't be able to tell the difference, if that's what you're going for?

If that was intentional, try the link I put in my answer, it describes different scenarios for updating trees and grass data.

Follow this Question

Answers Answers and Comments

61 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 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 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Grass is aliased on one terrain but isn't on the other 0 Answers

Grass detail doesn't work 0 Answers

Auto grass placement not working properly 1 Answer

Interactive Grass with terrain tool 0 Answers

Terrain : Detail paint isn't working on Unity 2018.2.0b11 2 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