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 Wolfshadow · Apr 17, 2017 at 10:37 PM · gameobjectplayerprefsruntimesavingsave data

Save Datasets at runtime

Hello everyone,

I have been working on an application that stores contacts (just a fun project) and I am having trouble saving and then loading data in the application. What I need to do is be able to create gameobject clones at runtime(I can do this already), save those clones, and load them in the exact same spot with the same variables(name, telephone, address, etc.). So far I have played around with arrays, playerprefs, the whole deal, but keep running into problems. Can someone explain a synopsis(for lack of a better word) of how such a script would act, and maybe point me towards code I could use? Thank you, and good day.

Wolfshadow

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

2 Replies

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

Answer by sleepandpancakes · Apr 17, 2017 at 10:42 PM

I found this link helpful: http://nielson.io/2015/09/saving-games-in-unity/

Comment
Add comment · Show 4 · 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 Wolfshadow · Apr 17, 2017 at 10:48 PM 0
Share

this looks good...i'll take a look

avatar image Wolfshadow · Apr 18, 2017 at 01:03 AM 0
Share

@sleepandpancakes did you actually use this, and if so, would it address my problems? It looks like it was a fancier way to do playerprefs.

avatar image sleepandpancakes Wolfshadow · Apr 18, 2017 at 01:11 AM 0
Share

Yes I used this for my game, because it seemed to make more sense and be more flexible than PlayerPrefs. It works perfectly for me. That being said, I've never actually used PlayerPrefs :P

avatar image Wolfshadow sleepandpancakes · Apr 18, 2017 at 01:17 AM 0
Share

ok, thank you

avatar image
0

Answer by NextVertex · Apr 18, 2017 at 11:54 AM

There are many possibilities to save/load data, but For your case, i think that you can use PlayerPref, it's the easiest way to save Data, but it's limited.

I Suggest you to save a prefab like EmptyContact (which contain the default contact image, the text for example MyName, ... (common to all contacts) ) and then, when you clone them, a script attached to this prefab will load the data saved by using PlayerPref.

I've created an application (personnal project too) and i had the EXACT same problem

You need to save, (for example before application exit), the number of contact there is. For example,

 GameObject[] ContactList = GameObject.FindGameObjectsWithTag("Contact");
 int AmountOfContact = ContactList.lenght;
 PlayerPref.SetInt("AmountContact",AmountOfContact);

I've created a script that is on each contact clone, for example, ContactData.cs

Start the script by writing this :

 public Text ContactCloneTitle;                                    
 public Text ContactClonePhoneNumber;                            
 public Image ContactCloneImg;                                        

As you can see, Text/image are NOT static, because EACH contact has his own Data.

Then, when your game start, just Load the data that we will define bellow.

To save the Data, use PlayerPref. Name your Pref for example "ContactCloneTitle"+IndexOfThisContact to have always a name different depending of the different clone.

Then , when you load the data, just use :

 ContactCloneName.text = PlayerPref.GetString("Contact"+IndexOfThisContact+"Name");
 ContactClonePhoneNumber.text = ...

Of course, this code is just an example. If your number of Contact is too high, this solution isn't the best, but this worked for me.

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

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

Related Questions

Saving usermade creations in game 1 Answer

Unity problem when i convert playerprefs save to the standard file io save 0 Answers

PlayerPrefs.GetString not saving past values 0 Answers

How do you save GameObject[]? 1 Answer

Need help with using Player Prefs to save number of coins collected. 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