Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 Komohu · Jun 02 at 03:30 PM · serializationinheritancesavingclassesclass instance

Saving class data without having lots of references?

 [System.Serializable]
 public class Level_Data
 {
     public string LVLID;
     public bool LevelComplete;[Space(20)]
     public string AnimationState;
 
     public Wire_Dictionary Wires;
     public Switch_Dictionary Switches;
     public Slider_Dictionary Sliders;
     public Moving_Part_Dictionary Moving_Parts;
     // switch dictionary
     // transmitter dictionary
     //cartirge dictionary
 
 }

I'm wanting to save level data for each level which includes the data for all the levelobjects in the level. The thing is each level is different, most levels will only include a few different levelobjects. So when I go to save a level I have an empty dictionary of every different levelobject that could be in a level and maybe only one or two actual populated dictionaries.


Is this fine to have it like this? it seems like a bit of a waste also it's a bit ugly in the inspector. Or is there a way to save just the levelobjects in that level and not have a refence to every possible levelobject that could be in the leveldata class.

For how the game works I would much prefer to save the leveldata all together and not have a file for each levelobject data.

I'm using a serialized dictionary as well which lets me serialize dictionaries. For example I have WireDictionary (WireData is variables I want to save for the wire) then on the wire object I just pass that onto it.

I've had a look at interfaces, and sub classes and I just can't get my head around it.

not sure what to do, having possible lots and lots of references that aren't gonna be used is a bit of waste of space.

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
0

Answer by rh_galaxy · Jun 03 at 03:05 AM

Just my thoughts here. You don't need a file for each levelobject data. You need to make an external editor that saves the relevant objects/data and then a loader that populate your data structures in your game.

I have my levels in text format, for clarity and easy parsing. Example:

 *MAPTYPE MISSION
 *MAPSIZE  50 60
 *MAPFILE  mission14.txt
 *TILESIZE 32
 *TILESET  ts_evil.png
 *MAXPLAYERS 2
 *PLAYERSTARTPOS   946   381
 *PLAYERSTARTPOS   864   163
 *LANDINGZONE   224  1884  3 CARGOBASE NOANTENNA 2 10 10
 *LANDINGZONE    96  1468  3 CARGOBASE NOANTENNA 1 20
 *LANDINGZONE   863   220  3 HOMEBASE ANTENNA
 *ENEMY 0
   *ANGLE         0
   *FIREINTERVAL  1800
   *SPEED         80
   *NUMWAYPOINTS  2
   *WAYPOINTSX      47   47
   *WAYPOINTSY    1721 1600
 ...

Sorry if I miss the point of your dictionaries, but you should focus on what your level consist of and save/load these things in your own code. Serialization can't beat that.
I'm not entirely sure what you want to do, but this is how I have done it and it may give you some new ideas. I don't use the Inspector for level editing.

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

147 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 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 to choose base class to make Inherit C# 2 Answers

Derived Class Serialization 3 Answers

Serialization Exception Error When Trying to Load 2 Answers

Serialization of inherited classes, could this work? 0 Answers

I can't make my sub class inherit from my base class [Mac + MonoDevelop] 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