Search Feedback

2708
votes

Serialization of Polymorphic Data Types

General

-

-

You should be able to Serialize polymorphic data types. A quick example:

[Serializable] class Base { public int myInt; }
[Serializable] class Derived : Base { public string myString; }

class MyBehaviour : MonoBehaviour
{
public Base _myBase = new Derived(); // Error... This will NOT work, only myInt will be saved.
}

ScriptableObject does not solve this issue because they cannot be saved into prefabs. Full post on this subject here: http://www.codingjargames.com/blog/2012/11/30/advanced-unity-serialization/.

Please consider this when rewriting the serialization to support nested prefabs!

Comments (47)

  1. 9f2de05ce2a6cc5f5b5a64aa8aade1a3?d=mm

    Zharradan

    Nov 27, 2017 10:45

    After discovering this the hard way and coming from a web background where this is normal and easy to do, I'm surprised this is not yet a feature of Unity. It feels like a key piece of the puzzle is missing.

    I understand that many of Unity's subsystems are built on the original serialisation system so it's probably a huge pain to upgrade now, but from a developer point of view it seems like we're having our hands tied behind our back. Is there any chance this could be looked into?

  2. 21448c4be0ee84cd5ad0558811c9be81?d=mm

    s-ta-c

    Nov 21, 2017 18:05

    Still nothing.
    I'm switching to Unreal. Good luck with ignoring your community.

  3. 38094335cb7c5bc3a9fa46926958f326?d=mm

    Polymo

    Nov 20, 2017 23:41

    It's starting to get ridiculus how long they are not trying to fix this. ScriptableObjects are nice, but they are not a replacement.

  4. 67cafeccd2e93148be7832e5ba5df51d?d=mm

    MaxGuernseyIII

    Nov 15, 2017 17:52

    Not supporting this violates the contract of SerializableAttribute just like not supporting circular references in object graphs.

    If you aren't going to support Serializable, you should just create a different interface to make that explicit.

  5. 67195a1a7dfa9eef8563f70a76c92a58?d=mm

    change

    Jul 31, 2017 10:49

    why not?

  6. Bd8b27c07a270dc81f2f370d7f2bfab9?d=mm

    Serhii-Horun

    Jul 29, 2017 10:23

    +8 votes from me.

  7. 78ed265f0b33e2208570927bc7b5dcb4?d=mm

    HexPix

    Jun 27, 2017 20:54

    This has been posted as a request since 2002. The community is begging for the very much needed overhaul to the serialization system. This suggestion alone has almost 2500 votes; nevermind the countless others on the same subject of basic serialization stuff unity should be able to do. Yet...Nothing... Even as a beginning developer, just finishing my first commercial-release game, this is making me seriously consider switching to Unreal4... If I'm going to spend the time to learn this, might as well learn the right stuff, in an engine that actually has a future... And respect for the community's needs regarding the engine's features; neither of which I'm seeing here in Unity. =(

  8. 21448c4be0ee84cd5ad0558811c9be81?d=mm

    s-ta-c

    May 28, 2017 19:16

    If this doesn't get implemeted soon, I may switch to unreal, or godot, or jıst any pther engine that has a sane way of scripting.
    +5 votes from me.

  9. Cfc92d15d6e1d20ea0afb32f27ed25d9?d=mm

    nuverian

    May 25, 2017 19:01

    I want 100 votes more to put here

  10. C1add2ff230213b25de9d56e8f77b97b?d=mm

    Aggressor

    Jan 23, 2017 15:52

    I'm out of votes but I support this!

Your opinion counts

Help us make things better. Share your great idea for improving Unity or vote for other people’s.

Log in to post a new idea

Categories

All

(9469)

2D

(244)

Ads

(43)

AI & Navigation

(74)

Analytics

(109)

Animation

(338)

Asset Store

(249)

Assets

(499)

Audio

(161)

Cloud Build

(108)

Collaborate

(36)

Docs & Tutorials

(208)

Editor

(2183)

Everyplay

(13)

Game Performance Reporting

(15)

General

(839)

Graphics

(794)

GUI

(375)

Input

(153)

Licensing

(80)

Networking

(165)

Physics

(354)

Platforms

(416)

Profiling & Optimization

(72)

Runtime

(167)

Scripting

(1057)

Terrain

(155)

WebGL

(135)