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 /
  • Help Room /
avatar image
0
Question by mfarrell806 · Dec 12, 2016 at 05:33 PM · loading filesave game

How to SAVE to user defined file Name, and then Load any other saved game by user Selection

Sorry for asking this, however I've looked at a dozen or more ave/Load examples.

I'm new to Unity, and I have not seen a single example that

A) works and or provides sample script that works without errors.

B) none actually show working example of prompting the user for a NAME of the saved game, OR ask the player what game to load.

The closest I've fount is the script below, I know it is saving the game, however I can't tell if it is actually loading the name.

How do I get the script to ask the player for saved game name to save, or load?

Thanks!

My guess is that I'm missing something really simple (stupid) that is preventing me from assigning a name to the saved game, and then recalling it at the load game function.

 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 using System.Runtime.Serialization.Formatters.Binary;
 using System.IO;
 
 [System.Serializable]
 public class Game
 {
 
     public static Game current;
     public CharacterInfo knight;
     public CharacterInfo rogue;
     public CharacterInfo wizard;
 
     public Game()
     {
         knight = new CharacterInfo();
         rogue = new CharacterInfo();
         wizard = new CharacterInfo();
     }
 
 
     public static class SaveLoad
     {
 
         public static List<Game> savedGames = new List<Game>();
 
         //it's static so we can call it from anywhere
         public static void Save()
         {
             SaveLoad.savedGames.Add(Game.current);
             BinaryFormatter bf = new BinaryFormatter();
             //Application.persistentDataPath is a string, so if you wanted you can put that into debug.log if you want to know where save games are located
             FileStream file = File.Create(Application.persistentDataPath + savedGames); //you can call it anything you want
             bf.Serialize(file, SaveLoad.savedGames);
             file.Close();
             Debug.Log("Game Saved");
         }
 
         public static void Load()
         {
             if (File.Exists(Application.persistentDataPath + savedGames))
             {
                 BinaryFormatter bf = new BinaryFormatter();
                 FileStream file = File.Open(Application.persistentDataPath + savedGames, FileMode.Open);
                 SaveLoad.savedGames = (List<Game>)bf.Deserialize(file);
                 file.Close();
                 Debug.Log ("Game Opened");
             }
         }
     }
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 SoraMahiro · Dec 12, 2016 at 05:40 PM 0
Share

I'm just putting this out there, although you may know it, that a lot of times games will actually pull up the save data as a folder in a load section. Now if you do understand this, I am curious why you don't want to do that, or is that what you're trying to do?

avatar image SoraMahiro · Dec 12, 2016 at 05:59 PM 0
Share

Oh, okay now I understand. Have you tried setting a text area event in the GUI of the save?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by mfarrell806 · Dec 12, 2016 at 05:50 PM

What I would ideally like to have happen....

When user clicks SAVE button, I want them to have a chance to give the saved game a NAME. The above posted code, does save the gave, however no user defined name.

The load button, as far as I can tell doesn't work because, it never asks for a file name to load, so how will it ever load the game the user saved?

So I want the button (script) to Prompt for a name to Save As... In the default save folder is fine.

And the Load Button to as the user which game to load.

It really should NOT e this difficult to get this information for such a widely popular game engine. Or does no one ever save their games with a name? (rhetorical question, because I'm pretty simple that way)

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 mfarrell806 · Dec 12, 2016 at 07:28 PM 0
Share

The code I posted is exactly what I have.

I've tried some other save/load codes as well that either produce too many errors on compile, or just do not work at all.

I am new to all of this, so any code that isn't well commented, is mostly useless. And even when well written the pieces I've found do not appear to work, and there are no clear examples of this in the Unity samples provided. Almost as if no one, ever actually saves a game in any manner that is useful.

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

81 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 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 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 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How do I load the game? 0 Answers

How do you handle running loops and instantiated objects when saving your game? 0 Answers

Is there any way to recreate the executable? 0 Answers

Issues when loading sub assets from an AssetBundle 0 Answers

Google Play Games Save Games not working 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