Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 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 /
avatar image
0
Question by TJFal · Jan 24, 2018 at 02:21 PM · scripting problemterraindataterrain-editor

Why isn't the DetailPrototype being added through a script waving?

I have created an EditorWindow script to create a terrain object in my scene. The script uses a block of information that I am storing in another game object. The game object with the information script on it gives inputs for DetailPrototypes that I want to add to the terrain. This all works fine, except that any prototypes I add to this terrain in this way do not sway when being used with the "Grass" render mode. However, if I then manually create a prototype in the normal inspector interface, then the prototype does indeed wave.

Is there something I am not "turning on" in the DetailPrototype object when I adding it in the script?

Here is the function where the terrain is created (look for the "Initialize Details" portion):

     void CreateTerrain()
     {
         if (GOInitializer == null) return;
         if (GOInitializer.GetComponent<TerrainConstructorSettings>() == null) return;
         if (Settings == null) InitializeSettings();
 
 
         // Get rid of old version of the Terrain  --------------------------------------------
         WorldName = Settings.WorldName;
         string TerrainName = WorldName + "_Tile_" + Position.X.ToString() + "_" + Position.Z.ToString();
         if (GameObject.Find(TerrainName) != null)
         {
             GameObject oldgo = GameObject.Find(TerrainName);
             DestroyImmediate(oldgo);
         }
 
         // Initialize the Terrain Data  ------------------------------------------------------
 
         TDATA = new TerrainData();
         TDATA.heightmapResolution = Settings.HeightmapResolution;
         TDATA.alphamapResolution = Settings.AlphamapResolution;
         TDATA.SetDetailResolution(Settings.AlphamapResolution, 8);
         AssetDatabase.CreateAsset(TDATA, "Assets/Resources/" + WorldName + "/TerrainData/" + TerrainName + ".asset");
 
         TDATA.SetHeights(0, 0, GenerateHeightmap());
 
         // Initialize the textures ------------------------------------------------------------
         
         SplatPrototype[] sprot = new SplatPrototype[Settings.terrain_textures.Length];
 
         for (int i = 0; i < Settings.terrain_textures.Length; i++)
         {
             TextInfo TI = Settings.terrain_textures[i];
             sprot[i] = new SplatPrototype();
             sprot[i].texture = TI.tex0;
             sprot[i].normalMap = TI.texn;
             sprot[i].tileSize = new Vector2(TI.scale, TI.scale);
         }
         TDATA.splatPrototypes = sprot;
 
         // Initialize the details  ------------------------------------------------------------
         DetailPrototype[] DPROTS = new DetailPrototype[Settings.terrain_Details.Length];
         for(int i = 0; i < DPROTS.Length; i++)
         {
             DPROTS[i] = new DetailPrototype();
             DPROTS[i].renderMode = Settings.terrain_Details[i].mode;
             if (DPROTS[i].renderMode == DetailRenderMode.GrassBillboard)
             {
                 DPROTS[i].prototypeTexture = Settings.terrain_Details[i].grass_tex;
             }
             else
             {
                 DPROTS[i].prototype = Settings.terrain_Details[i].prefab;
             }
             if (DPROTS[i].prototype != null) DPROTS[i].usePrototypeMesh = true;
             DPROTS[i].bendFactor = 1f;// Settings.terrain_Details[i].bendFactor;
             DPROTS[i].dryColor = Settings.terrain_Details[i].dry_color;
             DPROTS[i].healthyColor = Settings.terrain_Details[i].healthy_color;
             if (Settings.terrain_Details[i].minWidth != 0) DPROTS[i].minWidth = Settings.terrain_Details[i].minWidth;
             if (Settings.terrain_Details[i].maxWidth != 0) DPROTS[i].maxWidth = Settings.terrain_Details[i].maxWidth;
             if (Settings.terrain_Details[i].minHeight != 0) DPROTS[i].minHeight = Settings.terrain_Details[i].minHeight;
             if (Settings.terrain_Details[i].maxHeight != 0) DPROTS[i].maxHeight = Settings.terrain_Details[i].maxHeight;
 
         }
         TDATA.wavingGrassAmount = 0.5f;
         TDATA.wavingGrassSpeed = 0.5f;
         TDATA.wavingGrassStrength = 0.5f;
 
         TDATA.detailPrototypes = DPROTS;
         TDATA.RefreshPrototypes();
 
         // Add TreePrototypes  ------------------------------------------------------------
 
         TreePrototype treeproto = new TreePrototype();
         treeproto.prefab = Settings.Tree1;
 
         TDATA.treePrototypes = new TreePrototype[]
         {
                 treeproto,
         };
 
         // Create the terrain object and set Terrain Parameters  ---------------------------------------------------------
 
         TDATA.size = new Vector3(Settings.Length, Settings.Height, Settings.Length);
         var newTerrainGameObject = Terrain.CreateTerrainGameObject(TDATA);
         newTerrainGameObject.transform.position = new Vector3(Position.X * Settings.Length, 0, Position.Z * Settings.Length);
         newTerrainGameObject.name = TerrainName;
 
         T = newTerrainGameObject.GetComponent<Terrain>();
 
         T.terrainData.RefreshPrototypes();
         T.basemapDistance = 1000f;
         T.treeDistance = 1000f;
         T.heightmapPixelError = Settings.PixelError;
         T.reflectionProbeUsage = UnityEngine.Rendering.ReflectionProbeUsage.Off;
         T.detailObjectDistance = 200f;
 
         CompleteTerrainShader cTS = newTerrainGameObject.AddComponent(typeof(CompleteTerrainShader)) as CompleteTerrainShader;
         cTS.AutoBakeNormalMap = false;
         cTS.AutoBakeColorMap = false;
         cTS.Profile = Settings.cTS_Profile;
 
         T.Flush();
 
         // Save the game object as a prefab to the resource folder
         PrefabUtility.CreatePrefab("Assets/Resources/" + WorldName + "/" + TerrainName + ".prefab",newTerrainGameObject);
     }
Comment
Add comment · Show 1
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 chadfranklin47 · Nov 17, 2020 at 02:24 AM 0
Share

Any chance you found a solution?

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.

Follow this Question

Answers Answers and Comments

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

Related Questions

How expand the terrain palette of textures 1 Answer

Is there a way to create multiple terrains that use the same settings? (eg textures, grass wind settings) 0 Answers

Edit terrain by script?? 0 Answers

How do you make the material in the Terrain detail prototype properties update after runtime? 1 Answer

Preserving terrain details after stopping game. 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