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 IgorAherne · Oct 29, 2014 at 04:53 AM · serializationclassstaticsingleton

Serialization of Singleton vs Static class in Editor

When do I use Singleton and when should I use a static class when working with unityEditor? How easy is it to serialize data with each one?

Thank you

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
Best Answer

Answer by SamuZen · Oct 29, 2014 at 05:28 AM

At My Editor Scripts i use Static Class ... all public fields get serialized automatically and for private fields just use [SerializeField]

the question about Singleton Vs Static ... at my point of view, static i just use to hold string data ... and Singleton when my class need the functions ...

if is just for a bunch of String fields ... i say go for static, but if you need to pass data structure for List or Dictionary , you do at the initialization of the Singleton ...

 using UnityEngine;
 public class SomePerson : MonoBehaviour {

     //This field gets serialized because it is public.
     public string name = "John";

     //This field does not get serialized because it is private.
     private int age = 40;

     //This field gets serialized even though it is private
     //because it has the SerializeField attribute applied.
     [SerializeField]
     private bool hasHealthPotion = true;

     void Update () {
     }
 }
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 SamuZen · Oct 29, 2014 at 08:08 PM 0
Share

try put [SerializeField] before the field ...

can you post some of your code ??

avatar image AndreiMarian · Jan 24, 2018 at 11:36 AM 1
Share

Static classes can contain only static members, public fields are not serialized.

avatar image Bunny83 AndreiMarian · Jan 24, 2018 at 11:55 AM 0
Share

Right, this answer is more than confusing. Static classes are never serialized by almost any serialization system. This includes Unity's serialization system.


The question was specifically about singletons and editor scripts but the example is neither a singleton nor an editor script.

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

28 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

Related Questions

do Static classes get serialized? 0 Answers

Unserialized private variable values from static instance persist when exiting play mode 1 Answer

Can a static class have an Update() function which Unity calls automatically? 1 Answer

Writing an extension method for a class. Is it possible? How? 3 Answers

Inpsector missing variables from a Serializable class? 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