Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 iamthecoolguy11 · Oct 05, 2013 at 04:17 AM · saveobjectsloading

Saving lots of objects

I know this is a hard one so a big thanks in advance. So I have this game called borda and the world is made of many many cubes. I can't figure out how to save it all with out the game crashing. So if you guys can help me have unity save and load all this stuff I would be very thankfull.

This is how it looks

alt text

alt text alt text

cubes.png (86.4 kB)
saves.png (8.7 kB)
Comment
Add comment · Show 5
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 tw1st3d · Oct 05, 2013 at 04:18 AM 0
Share

What exactly is crashing? It saving the cubes?

avatar image iamthecoolguy11 · Oct 07, 2013 at 04:17 AM 0
Share

it mainly needs to save positions. It dose not have to save any of the rotations or anything but yes it is saving the cubes and trees and other stuff I place down in the game. I can set it up to be a child of a object if you need it to be.

avatar image TrickyHandz · Oct 07, 2013 at 04:26 AM 0
Share

What methodology are you currently using to attempt to save? Text File, X$$anonymous$$L, Serialized binary?

avatar image iamthecoolguy11 · Oct 07, 2013 at 11:20 PM 0
Share

I tried players prefs and it was too much data for it to obtain at once and ended in freezing the game. So I believe its X$$anonymous$$L;

avatar image Doeko · Oct 08, 2013 at 08:54 AM 0
Share

I don't see how X$$anonymous$$L serialization of even tenthousands of objects's transforms would crash the scene. It shouldn't even take very long on a halfway decent CPU (maybe 10 seconds?).

You need to be more specific in what you are currently doing.

By the way playerprefs is not for storing huge amounts of data like this. You need to create your own files.

1 Reply

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

Answer by tw1st3d · Oct 08, 2013 at 12:06 AM

Sounds like you'll want to use custom data saving with a Coroutine. Something along the lines of this:

 using UnityEngine;
 using System.Collections;
 using System.IO;
 
 public class SaveGame : MonoBehavior
 {
     public GameObject[] cubes;
     protected string savename = "savegame";
     
     private void Start()
     {
         cubes = FindGameObjectsWithTag("Floor");
     }
     
     public IEnumerator Save()
     {
         foreach(GameObject cube in cubes)
         {
             Vector3 pos = cube.transform.position;
             Quaternion rot = cube.transform.rotation;
             
             AddCube(pos, rot);
             
             yield return new WaitForSeconds(0.01f);
         }
     }
     
     public void AddCube(Vector3 pos, Quaternion rot)
     {
         float[] xyz = new float[3], hpb = new float[3];
              // Pos                 Rot
         xyz[0] = pos.z; xyz[1] = pos.y; xyz[2] = pos.z;
         pos[0] = rot.z; pos[1] = rot.y; pos[2] = rot.z;
     
         if(File.Exists("saves/" + savename + ".txt"))
         {
             using(StreamReader saveFile = File.OpenText("saves/" + savename + ".txt"))
             {
                 foreach(float item in xyz)
                 {
                     saveFile.Write(item.ToString("R"));
                 }
                 saveFile.Write("-"); // Separator
                 foreach(float item in hpb)
                 {
                     saveFile.Write(item.ToString("R"));
                 }
                 saveFile.Write("\n"); // Line break
             }
         }else{
             using(StreamWriter saveFile = File.CreateText("saves/" + savename + ".txt"))
             {
                 foreach(float item in xyz)
                 {
                     saveFile.Write(item.ToString("R"));
                 }
                 saveFile.Write("-"); // Separator
                 foreach(float item in hpb)
                 {
                     saveFile.Write(item.ToString("R"));
                 }
                 saveFile.Write("\n"); // Line break
             }
         }
     }
 }

Now, prewarning: I didn't have a computer with Unity to test this to make sure it will work, but you can probably take it from here and fix it up to work how you want it to.

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 iamthecoolguy11 · Oct 08, 2013 at 09:42 PM 0
Share

Thank you but im sorry I forgot to put this in the thing but can you make it in java cus I dont know any C# yet sorry.

avatar image tw1st3d · Oct 08, 2013 at 10:55 PM 1
Share

No, sorry. I have no idea how to do this in Unityscript. But honestly, C# is far more efficient and useful than Unityscript, along with being faster with large projects. You may want to study up.

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

18 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

Related Questions

Saving and loading game with PlayerPrefs 1 Answer

Save selected objects to a separate scene? 0 Answers

What is the best way to save a scene and load it later? 0 Answers

PlayerPrefs Question 0 Answers

SAVE OBJECTS IN ARRAY 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