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 /
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

Could you post the code? I dont know how I to convert the 2d array of floats to a 1D array of bytes, Thanks!

avatar image Eric5h5 · Jun 01, 2011 at 06:04 AM 0
Share

@logty: The code has some project-specific stuff in it, but the idea is that you convert the 0.0-1.0 float range to a 0-65535 integer range using Lerp, then with this number (call it "p"), do "p / 256" for the low byte and "p % 256" for the high byte.

avatar image logty · Aug 09, 2011 at 01:45 AM 0
Share

Never $$anonymous$$d, I got the code, thanks!

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

I have tried arrays, but it didn't seem to work because I can't find a way of saving a 2d array (the terrain heights). Any ideas?

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

So far I have tried using player prefs, with a huge (like 263,169 loops) for loop, but that takes ~10 $$anonymous$$utes I'd say. I have also tried using the SimpleDictionary on the Unity wiki but again the same problem. What sort of database engine do you mean?

avatar image Meltdown · May 31, 2011 at 07:54 PM 0
Share

When I mean a database engine I mean $$anonymous$$ySQL/SQL Lite etc. I assume since you are only storing terrain data on the local players computer, and not on a server somewhere, you'll be ok to talk directly to the database. Do a search on Unity answers/Google for using $$anonymous$$ySQL with Unity and you'll be good to go. Good luck :p

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

Could you explain some? I looked around, but I am not sure how to make a simple image object.

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

Right now it seems it will save it to whatever location the program is using, so scour your unity folder or use the windows build in searcher.

Try file.wri$$anonymous$$llbytes("C:\\Hello.ini", BigArray);

It will save it to your C:\ Drive. Note that two \\'s are required as the first one opens a special character generator (meaning it's how you can do "\"I like you\"" to get a text or string to go "I like you".

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

7 People are following this question.

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

Related Questions

Start another thread for a function 1 Answer

How to save achievments in game 2 Answers

saving highscores 1 Answer

Get Height of Terrain in Script 1 Answer

When should I save data 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