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 /
This question was closed Oct 23, 2013 at 01:25 AM by meat5000 for the following reason:

Long unattended QA with too broad a question

avatar image
0
Question by brandon199511 · Feb 12, 2012 at 06:40 AM · rotationpositionplayersaveload

Saving System?

Hello, I am trying to make a saving system for my game. What I need to save is the players position, as well as its child's (which should just only need the players). I also need to be able to save all the objects created in the game. Since this is dynamic, so will the code. This meaning, the users can spawn objects. Therefore I would need the positions and rotations of every spawned object. Is this possible? I don't think playerprefs can handle this much of a saving system. Also, the system needs to be able to reopen this back up when the user uses a load feature, which I would also need.

If anyone can help me with a tutorial or something on the basics of this, I might be able to just get the rest of it on my own, if not I can just make another question on the forums or here asking the part I need help on.

Thanks, Brandon

Comment
Add comment · Show 4
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 flamy · Feb 12, 2012 at 07:08 AM 0
Share

check for player prefs in documentation

avatar image brandon199511 · Feb 12, 2012 at 08:17 PM 0
Share

I have, I don't think they can hold what I am trying to do.

avatar image flamy · Feb 12, 2012 at 08:19 PM 0
Share

then try it with streamreader adn streamwriter class from c#(check msdn for info)

avatar image unity_BUJQdslYm7EuFQ · Jul 17, 2021 at 08:57 AM 0
Share

I think that it is better to use serialisation instead of PlayerPrefs Here is code that I`m using:

 using System.Runtime.Serialization.Formatters.Binary;
 using System.IO;
 using UnityEngine;
 
 public static class FileManager
 {
     public static void SetUpData<T>(T Data, string Path)
     {
         BinaryFormatter formatter = new BinaryFormatter();
         FileStream file = File.Open(Path, FileMode.OpenOrCreate);
         formatter.Serialize(file, Data);
         file.Close();
     }
     public static T GetData<T>(string Path)
     {
         if (File.Exists(Path))
         {
             BinaryFormatter formatter = new BinaryFormatter();
             FileStream file = File.Open(Path, FileMode.Open);
             T data = (T)formatter.Deserialize(file);
             file.Close();
             return data;
         }
         return default(T);
     }
 }
 [System.Serializable]
 public class Data
 { 
   //place all that you need to save here as variables
 }

An example:

 public class ExampleClass : MonoBehaviour
 {
     public Data data;
     public const string FileName = "/PlayerData.data";
 
     private void Start()
     {
         data = FileManager.GetData<Data>(Application.persistentDataPath + FileName);
     }
 
     //do smth
 
     public void Save()
     {
         FileManager.SetUpData(data,Application.persistentDataPath+FileName);
     }
 }
 
 [System.Serializable]
 public class Data
 {
     public Vector3 PlayerPosition;
     public Vector3 ChildPosition;
 
     public List<SpawnedObject> spawnedObjects = new List<SpawnedObject>();
 }
 public struct SpawnedObject
 {
     public Vector3 Position;
     public Vector3 Rotation;
 }


1 Reply

  • Sort: 
avatar image
0

Answer by FTheCloud · Feb 12, 2012 at 09:13 PM

Flamy's right. You've got to use player prefs. But for what you want to do its going to take a lot of work.

What you need to do is store the object's position and rotation values in the player prefs. Then when you start up your scene again you set the object's position and rotation values according to the ones you previously stored.

It will be a ton of work though if you have a lot of objects in which you want to save their position and rotation in the scene. Player prefs should be able to handle the amount of information.

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 brandon199511 · Feb 12, 2012 at 10:24 PM 0
Share

Any legit examples on playerprefs?

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

Game Object won't match rotation of new positions transform 1 Answer

Object rotation different from last save? 0 Answers

Call Other Object to Self 2 Answers

how to save last position for the player before he die 2 Answers

How can I save and load a player's position? 5 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