• 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 Jeremy 2 · Jun 19, 2010 at 05:27 PM · terrainsaveloaddataheight

Saving a randomly generated Terrain

I have a randomly generated terrain and a functional Save/Load system using XML. In order to save the generated terrain, I tried serializing the heights in XML but it gives me an error (2d arrays aren't accepted as primitives). T$$anonymous$$s is basically what I did :

var heights;

var xRes = Terrain.activeTerrain.terrainData.heightmapWidth; var yRes = Terrain.activeTerrain.terrainData.heightmapHeight; heights = Terrain.activeTerrain.terrainData.GetHeights(0, 0, xRes, yRes);

And then the data is serialized.

I tried serializing other types like int, string or even Array() and it works, so it's not the Saving system that causes the problem.

Are there any other methods to save t$$anonymous$$s type of data? Would exporting the heightmap on the hard drive and importing it when loading the game work? If so, how can I export the heightmap from script?

For reference, t$$anonymous$$s is the Save/Load code I'm using : http://www.unifycommunity.com/wiki/index.php?title=Save_and_Load_from_XML

Thanks for any answers.

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 qJake · Jun 19, 2010 at 05:58 PM 0
Share

That script can't handle 2D array serialization, obviously, so you'd either need to modify the script, or write your own serialization for it.

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Tetrad · Jun 19, 2010 at 11:15 PM

You could use .NET's built-in serialization.

http://msdn.microsoft.com/en-us/library/4abbf6k0(v=VS.71).aspx

Basically, save your data using BinaryFormatter.

Example here: http://msdn.microsoft.com/en-us/library/system.runtime.serialization.formatters.binary.binaryformatter.aspx

Comment
Add comment · 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

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

No one has followed this question yet.

Related Questions

Loading a list into unity 0 Answers

How to save and load the game of the corresponding player by Serialization 1 Answer

Create a terrain prefab? Saving a terrain? No? 1 Answer

How to save and load any data type? 1 Answer

(Unity Serializer)Save objects generated at runtime 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