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 originalNarf · Jan 02, 2013 at 11:24 PM · serializationinheritancemonobehaviour

Serialization and Inheritance: Great-GrandChild Class appears unserialized

I have something along the lines of:

 class Core : Monobehavior {
   //public int value;
 }
 
 class Variation : Core {
   //public int value;
 }
 
 class Specific : Variation {
   public int value;
 }

Alright, so, basically, I see different serialization depending on where value is declared, but only on the app. It's fine as a scene/prefab/re-imported asset bundle. This is driving me up the wall, and I don't know what experiments to try to figure out what's going on or what might be a work-around.

A bit more detail: value is set via the editor to something. Reliably, if it's declared in Core, it has the correct value when run on the device (android), and, reliably, it has a value of zero when declared in Specific - even if I set the default to, say, 10. Sometimes it has the correct value when declared in Variation, and I swear it depends on where I last declared it, although that's crazy - I'm pretty sure there's a pattern to the when, but I haven't been able to isolate it. It could have something to do with the code state when I create the asset bundle vs when I build-and-run, although I've tried to keep everything together.

Important Edit

The first guy who implemented our code for downloading and instantiating an asset bundle did a bunch of weird and complicated stuff I don't follow, and when I re-implemented it in the simple way recommended by Unity, everything worked.

So if you hit this question because you're having the same issue, maybe just scrap your download code and start over - however, first check to make sure all your info is in the prefab and asset bundle.

I'm leaving the question up in the hopes that I have time to dive into the wtf that is the prior code, and figure out what the difference is.

Comment
Add comment · Show 4
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 Bunny83 · Jan 02, 2013 at 11:51 PM 0
Share

That sounds really strange... I think i've never trieds a second level inheritance with serialization, but the way Unity's serialization works it should serialize them. I have to try this myself, but it's late here and i have to sleep ;).

Is it always 0 (the default value) on android? Have you tried other playforms? Actually this kind of problem shouldn't be platform specific, but who knowa ;)

avatar image originalNarf · Jan 03, 2013 at 12:08 AM 0
Share

Well, also, now, serious WTF: Got rid of Core (copied it into Variation), and now it doesn't matter if specificValue is in Specific or Variation, it's zero, whereas before, if I put it in the parent classes, it worked out. WTF.

avatar image Bunny83 · Jan 03, 2013 at 12:24 AM 0
Share

You don't really need the System.Serializable attribute since $$anonymous$$onoBehaviour derived classes are always serialized. $$anonymous$$aybe it causes this behaviour, but i don't think so.

Are you sure you don't set the values in Awake or Start or any other place?

avatar image originalNarf · Jan 03, 2013 at 01:49 AM 0
Share

Removed the Serializable attribute, everything is working as it was, including breaks.

I don't set the values in Awake or Start, and I got no errors when I privatized/protected the variable.

0 Replies

· Add your reply
  • Sort: 

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

9 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to call a function on all scripts which are derived from monobehaviour on awake and ondisable? 1 Answer

What is the most elegant solution to replace multiple inheritance for this? 0 Answers

Help with using JsonUtility.FromJsonOverwrite 1 Answer

Serializable class with coroutines? 1 Answer

How to store data in script and attach it later? 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