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
0
Question by dmmrekc · Oct 26, 2016 at 05:46 AM · save gamerandom gen

Save a randomly generated terrain to game file

Hello! I am currently working on a 2D Minecraft-esk game as a learning experience. I have gotten rather far on my own but I have gotten stuck on how to save my map (Blocks and player position). I created a random block generator (It's a bit of a mess, I know, but it works) The issue I am having is saving the prefab copies to a save file without the terrain regenerating on me every time. With all the save methods I have tried every single one just regenerated the terrain.

Bonus Info: I have the terrain generation script attached to my player so as soon as the player is rendered the terrain randomly generates.

using UnityEngine; using System.Collections; public class blockSpawn : MonoBehaviour { %|-1446747765_1|% public GameObject Grass; %|903217905_3|% %|136237991_4|% %|-1251951135_5|% %|-1426623343_6|% %|-2065649517_7|% %|-1819742777_8|% %|1906837029_9|% %|-1986051694_10|% %|1651827282_11|% %|-1108236652_12|% %|670030102_13|% %|-2029995424_14|% %|602125092_15|% %|-1586535938_16|% %|-1923784418_17|% %|-1864907346_18|% %|2135106283_19|% %|-1141352543_20|% %|-102703709_21|% %|1590346120_22|% %|467579366_23|% %|-2115044570_24|% %|-397939301_25|% %|2140486734_26|% %|-1756250263_27|% %|-1587411223_28|% %|686911334_29|% %|-1137264129_30|% %|-1738760240_31|% %|1299188956_32|% %|-1179186729_33|% %|-1930294853_34|% %|1411423665_35|% %|366522794_36|% %|-955403629_37|% %|-1381109886_38|% %|209607248_39|% %|46396959_40|% %|-335559266_41|% %|554706497_42|% %|-99270313_43|% %|2053780166_44|% %|435716658_45|% %|-1615331825_46|% %|823788486_47|% %|1405987283_48|% %|-2130050861_49|% { x = 0; %|23122755_52|% %|-1974208865_53|% %|-898427287_54|% %|-730124794_55|% %|-293419199_56|% %|969071082_57|% %|804195557_58|% %|-698426720_59|% //End of Update }

Comment
Add comment · Show 2
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 hexagonius · Oct 26, 2016 at 08:38 AM 1
Share

ok, what is this?

avatar image AlucardJay · Oct 26, 2016 at 08:52 AM 0
Share

Random Generation usually just involves a couple of variables that are fed into an equation. Ins$$anonymous$$d of sending ALL the terrainData, just send the values used in the equations (eg random seed). Let each client do the calculation. As long as you are not using Random.Range or value, each client will produce the same output.

and I would also like to know what this is you have pasted

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Pangamini · Oct 26, 2016 at 09:25 AM

You don't want to save prefabs directly, neither of level nor your player object. Unity doesn't natively support any savegame mechanics, but you can write your own.

Basically, you need to extract some data from your game, write it into a file, and later be able to load this data and recreate your game. You don't write entire prefabs, just all data needed to recreate it (and link it back to the game).

A robust automatic system (that utilizes reflection) might take some time, but you can put something simple together rather quicky.

If your level is a simple 2D array of blocks, you could just write: dimensions of your level one byte per block of your level (byte defining a type of the block) Write this data using System.IO library When reading, simply follow the same steps but reversed: Read level dimensions; Then read through the block data, recreating blocks in your game

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.

Follow this Question

Answers Answers and Comments

6 People are following this question.

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

Related Questions

Create an autosave/checkpoint feature for my game? 1 Answer

Lets talk multiplayer: General Questions? 2 Answers

Making a Script that places Objects at random possition but not at the same as a taken position 1 Answer

Save Game Folder 1 Answer

How to save some integers and bools when a scene is switched. 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