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
0
Question by kiriri · Oct 26, 2013 at 10:55 AM · terrainprocedural-generationterrain gensplatmaps

Get Terrain material / Set splat maps

Hi, I need to procedurally generate my terrains. In my case, depending on where the user clicks on a world map, different splat maps should be applied to the local terrain. How does one do this ?

This code :

 TerrainData t = gameObject.GetComponent<Terrain>().terrainData;
 t.splatPrototypes[0].texture = exampleTex;
 t.RefreshPrototypes();

..does exactly nothing.

So after some time to think, I got the idea to just change the Terrain material instead. However, since TerrainRenderer is an internal-sealed non Monobehaviour(eg it does not inherit from MeshRenderer and therefore cannot be gotten via .renderer) I can't see a way to get its' Material. Terrain.materialTemplate returns null, so that's not it either.

Any help would be appreciated on this. I'd go great lengths to finally be able to set my splatmaps via code.

[I also asked this question in the forums, but it got lost : http://forum.unity3d.com/threads/206902-change-terrain-splatmap-alphamap ]

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
2
Best Answer

Answer by dbc_orp_kids · Jun 13, 2016 at 12:46 PM

You can create a totally new SplatPrototype array and then set that in terrain data. For me this works.

 TerrainData t = gameObject.GetComponent<Terrain>().terrainData;
 SplatPrototype oldProto = t.splatPrototypes[0];
 
 SplatPrototype newProto = new SplatPrototype[1];
 newProto[0] = new SplatPrototype();
 // Copy parameters
 newProto[0].metallic = oldProto.metallic;
 newProto[0].normalMap = oldProto.normalMap;
 newProto[0].smoothness = oldProto.smoothness;
 newProto[0].specular = oldProto.specular;
 newProto[0].tileOffset = oldProto.tileOffset;
 newProto[0].tileSize = oldProto.tileSize;
 
 // Only the albedo texture is different:
 newProto[0].texture = exampleTex;
 
 // Set prototype array
 t.splatPrototypes = newProto;
 
 t.RefreshPrototypes();

Of course, if you have multiple splat prototypes in your terrain, you should duplicate them and put them into the new array in the same order as before.

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 smidlingPupin · Jan 27, 2019 at 02:05 PM 0
Share

Dont forget to rewrite other splatPrototypes as well (besides newProto[0]).

BTW, thanks so much for this answer! :)

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

Make part of terrain transparent. 1 Answer

Overly bright splat map replacement 2 Answers

How do I apply a splatmap to my terrain? 1 Answer

Unity Terrain GameObject versus Custom Terrain 1 Answer

A good terrain engine for Unity ? 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