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 13dnizinski · Oct 06, 2014 at 12:12 AM · gameobjectsaveload

I need to save and load GameObjects. How do I do this?

I have tried saving and loading through playerprefs, but I don't want the save to be stored in the registry. I tried serialization, but it doesn't work for gameObjects. I have even tried the Unity Serializer, but it does not work either since in my game, objects are being created and destroyed all the time. In my game, the player places newly instantiated wall sections in a multidimensional list. I need to be able to save where all the wall sections are with their rotations and materials. Is this even possible?

Comment
Add comment · Show 1
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 Baste · Oct 06, 2014 at 12:19 AM 1
Share

You probably don't want to save the gameobjects themselves - that's a lot of data. If you're just saving walls, you save the information you need about them, and create a format to save that to a file.

It looks to me like your walls are defined by their position, their rotation, and which of probably some predefined range of materials they use. That's 6 float coordinates, and one int specifying the material. Should not be to hard to prototype out a working solution.

3 Replies

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

Answer by Cherno · Oct 06, 2014 at 12:25 AM

Edit: Link to my free Save & Load Utility: SerializerHelper

Unity Serializer should work ok with instantiated objects (if you give the prefabs a Prefab Identifier). It seems to break down then and now, however.

It's true that you can't serializer things like GameObjects, Vector3s and Materials. However, workarounds are usually pretty easy. A position and rotation can just be represented as three integers (like posX, posY, posZ), Materials? Just save the Material name and/or file path in a string, and load it again when loading a saved game with Resource.Load. A GameObject can be represented with an unique ID int, and to load an instantiated GO you can save it's name and then look up this name in a dictionary that lists all names and the corresponding GO filenames in your project folder.

These are just examples, and it's how I do it and it worked well thus far. The multidimensional list needs to be flattened when serializing it, of course, and made multi-dimensional again after deserializing, but that's also easy.

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 13dnizinski · Oct 06, 2014 at 12:59 AM 0
Share

I think I will have to end up saving strings of the prefab name, materials, positions, and rotations just like you said. Unity Serializer seems to not work for my setup and your suggestion is the next best thing.

avatar image TRollinue · Mar 10, 2016 at 10:13 PM 0
Share

A GameObject can be represented with an unique ID int, and to load an instantiated GO you can save it's name and then look up this name in a dictionary that lists all names and the corresponding GO filenames in your project folder.

Could you elaborate on this?

avatar image Cherno TRollinue · Mar 10, 2016 at 10:35 PM 0
Share

I encourage you to take a look at my free save & load utility:

SerializeHelper

It is designed to $$anonymous$$ch users the basics of saving & loading any kind of data and is a great base framework to add your own functionality.

avatar image
1

Answer by chrismcrae5712 · Oct 06, 2014 at 12:18 AM

This isn't really an answer just a suggestion. I am currently in the works for the same setup. The best solution I have found is if you're making a game where players cannot access files then you should store everything in a database. If you wish to store GameObjects, then the best solution would be to store all the data for the GameObject's via MySQL database or similar. Goto youtube and search Unity3d with MYSQL and you'll get a bunch of tutorials on how to do this some even with gameobjects. The other way (if u dont care if players can access the files) then instantiate prefabs and make the gameobjects into prefabs.

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

Answer by Voxel-Busters · Aug 08, 2015 at 10:05 PM

You can directly serialize GameObject using our plugin Runtime Serialization for Unity. Its not just another serialization plugin which works only on custom c# objects. But what makes it special is its capablity to serialize Unity Objects like GameObject, MonoBehaviours, Textures, Prefabs etc. For more info about supported list, please check this link.

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

33 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

Related Questions

How to save/load references to components and prefabs 1 Answer

Save/Load Objects settings(position, rotation ...) 1 Answer

Hard question about saving and loading 1 Answer

Saving and Loading and assinging to gameobject 0 Answers

Saving and Loading Data with a for loop 2 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