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 /
  • Help Room /
avatar image
1
Question by exprt · Sep 10, 2015 at 03:25 PM · terrainruntimeterraindatapaintterrain-editor

Runtime terrain painting with SetAlphamaps = lag

Hi!

According to profiler, one call of TerrainData.SetAlphamaps takes 40ms to finish, when setting array of size: 20,20,3. No matter how big is updated fragment, it stutters my project. Alphamap resolution is 2048, but it lags also when it's 512.

I used single updates with small 1x1 fragments (4ms!), I used coroutines, read all post about SetAlphamaps function, but there was no working solution for me.

Function written by me draws road texture on terrain in runtime, from point to point. I think it is the simpliest way to build road in runtime. Is there any way to speed it up? Maybe better way to draw a simple road?

The most important questions are:

How the same function "SetAlphamaps" works smoothly in editor mode???

Why it's lagging in runtime?

If it can be done in editor, why not in game?

My code:

 function BuildRoad(p1 : Vector3, p2 : Vector3){ 
     var tData=Terrain.activeTerrain.terrainData; 
     var bSize=20; 
     var brush = new float[bSize,bSize,3]; 
     for(var x=0; x<bSize; x++){ 
     for(var z=0; z<bSize; z++){ 
         brush[x,z,0]=0.0; 
         brush[x,z,1]=0.0; 
         brush[x,z,2]=1.0; 
     }    
     } 
     var xx : int; 
     var zz : int; 
     var dir : Vector3 = p2-p1; 
     var length=dir.magnitude; 
     dir.Normalize(); 
     for(var i=0; i<length; i++){ 
         xx = ((p1.x+dir.x*i)/tData.size.x)*(tData.alphamapWidth-1); 
         zz = ((p1.z+dir.z*i)/tData.size.z)*(tData.alphamapHeight-1); 
         tData.SetAlphamaps(xx,zz,brush); 
     } 
     Terrain.activeTerrain.terrainData=tData; 
 }








Comment
Add comment · Show 4
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 Meer_Hamza · Jul 19, 2016 at 07:28 AM 0
Share

I have same issue. if you have solved it kindly share the solution here, it will be great of all of us thanks

avatar image exprt Meer_Hamza · Jul 19, 2016 at 08:01 AM 0
Share

Unfortunately no. Regardless of all optimizations, realtime terrain painting was unplayable. Believe me, it was a long journey through the internet. Ended up with generating procedural mesh for paths and roads :/

You can search for some 3rd party terrain systems..

avatar image Meer_Hamza exprt · Jul 19, 2016 at 10:16 AM 0
Share

Yeah i can understand been there for at least a week. But thanks for replying anyways, do you have any terrain system in ur $$anonymous$$d??

Show more comments

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

27 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

Related Questions

How to paint terrain via script in the new terrain system? 0 Answers

Unity Desert Sand Dunes 0 Answers

Terrain "Creating System" consuming infinite memory [Please Help] 0 Answers

Terrain settings resets on changing scene? 1 Answer

Can't Change The Smoothness of Terrain Layers 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