• 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 logty · May 31, 2011 at 07:01 PM · terrainsavesaving

How do I quickly save a large number of variables?

I have a large number of variables (263,169 to be exact, what I am trying to save is the terrain heights), and every way I have tried saving them has not seemed to work because it takes way to long. Does anyone have an easy way of saving them? Thanks!

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

5 Replies

· Add your reply
  • Sort: 
avatar image
3
Best Answer

Answer by Eric5h5 · Jun 01, 2011 at 05:17 AM

Convert the 2D array of floats to a 1D arrays of bytes, then use File.WriteAllBytes with that array. (That's what Fractscape does when saving the terrain heightmap, and it takes a fraction of a second to export a 513x513 terrain.)

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 logty · Jun 01, 2011 at 05:52 AM 0
Share
avatar image Eric5h5 · Jun 01, 2011 at 06:04 AM 0
Share
avatar image logty · Aug 09, 2011 at 01:45 AM 0
Share
avatar image
0

Answer by KennSan · May 31, 2011 at 07:42 PM

Have you tried using an array?

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 logty · May 31, 2011 at 07:51 PM 0
Share
avatar image
0

Answer by Meltdown · May 31, 2011 at 07:43 PM

What are the different ways you have tried saving them? For that amount I'd suggest using a database engine of some sort.

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 logty · May 31, 2011 at 07:49 PM 0
Share
avatar image Meltdown · May 31, 2011 at 07:54 PM 0
Share
avatar image
0

Answer by Igotkidsuknow · May 31, 2011 at 08:22 PM

Most people tried some sort of image map and that seems to work fine. Have you tried saving the data as a simple image object? Do a search for terrain image map here in the forums. That might help.

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 logty · Jun 01, 2011 at 04:44 AM 0
Share
avatar image
0

Answer by logty · Jun 01, 2011 at 02:43 PM

Okay, I tried making my 2d array into a 1D array, and it seems to work, but where does it save my file? Here is the code, thanks!

 import System.IO;
 var TerrainD:Terrain;
 function Start () {
 
 var TD = TerrainD.terrainData;
 var heights:float[,] = TD.GetHeights(0,0,512,512);
 var BigArray = new byte[263169];
 print(BigArray.length);
 var Inte = 0;
 for (var y : int = 0; y < 512; ++y) {
     for (var x : int = 0; x < 512; ++x) {
         BigArray[Inte] = Mathf.Round(Mathf.Lerp(0,65535,heights[y,x]));
         Inte+=1;
     }
 }
 print(Time.time);
 // Apply all SetPixel calls
 File.WriteAllBytes( "/Hello.ini", BigArray);
 }

To be more exact, where is it saving Hello.ini? Also, the code doesn't seem to be working because it doesn't seem to be creating a file.

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 GADefence · Jul 17, 2011 at 07:44 PM 0
Share

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Not save changes to the terrain in the editor 1 Answer

Object falling through terrain with script 2 Answers

Saving player stats for each level, static class or not ? 1 Answer

Save variable value. 1 Answer

Sharing Violation On Path 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