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 jefequeso · Sep 28, 2015 at 06:38 AM · serializationloadingsaving

Some help with saving and loading in Unity

I'm reading up on how to save and load in Unity, and I'm having a little trouble understanding it. Thus far, I understand that data must be serialized. But let's say you have a class called "Enemy," and that class stores variables for the enemy object's position, rotation, and health. How do you serialize this class for multiple enemies? And when you load the data, how do you know which data goes to which enemy?

Sorry if this is a stupid/misguided question, but I'm very new to saving and loading.

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

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Cherno · Sep 28, 2015 at 11:04 AM

First of all: I invite you to take a look at my SerializeHelper aset, it's free and is aimed at teaching the basics of datas serializing and saving/loading functionality for any game. You will spend a days just understanding it and reading up on topics on MSDN; there's no way around it. Serialization in combination with Unity is a fairly advanced and complex topic with numerous pitfalls. No quick and easy works-for-all solution there :)

The question you asked is answered by SerializeHelper. Basically, you have to go through all the GameObjects that need to have some of their data saved, and create a new instance of a container class for each which holds the data. This instance can then be added to a list or array and serialized. You also have to find a way to identify each GameObject between saving and loading so the right data can be given back to the right GameObject. SerializeHelper does this by generating a unique ID via GUID.

Comment
Add comment · Show 3 · 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 jefequeso · Oct 05, 2015 at 02:41 PM 0
Share

Thanks for your response! In your opinion, would it be better to simply use one of the Serializers provided by the Unity community rather than trying to code my own?

avatar image Cherno jefequeso · Oct 05, 2015 at 03:37 PM 1
Share

Let me put it this way:

Generally, there is no better way to learn than trying things out for yourself. However, it can't hurt to also look at how other people have done things. In the end, no asset provided to you will be an exact fit for the game you envision, there will always be the need for customization. When writing SerializeHelper, I started with simple serialization of simple data: some strings, some ints etc. However, in Unity, we have to deal with Unity-specific classes ($$anonymous$$onoBehaviors, Vector3, GameObjects and so on), and these require workarounds because they can not be serialized as-is. For some classes, this is relatively simple (although still a daunting task for someone with no experience), for others, less so. I got a good many ideas from the great "UnitySerializer", an asset that is sadly no longer supported but is still a treasure chest of information.

tl;dr: You may want to $$anonymous$$ch you the basics yourself by experimenting with some simple serialization operations, and once you go in deeper, you can use that knowledge to understamnd how other people have done it and go from there ins$$anonymous$$d of trying to figure out everything yourself.

avatar image jefequeso Cherno · Oct 07, 2015 at 02:23 AM 0
Share

Ok, I will keep that in $$anonymous$$d. Thanks very much :)

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Serializing / deserializing large lists 0 Answers

How to deserialize after I've added more members to a class 0 Answers

Saving and Loading Various Things 1 Answer

Serialized Data Not Saving on Android Build 0 Answers

Issue loading serialized config.dat from persistant Data 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