{"author_link":"\/users\/ii-p","author_name":"II-P","author_uid":"ii-p","comments":[],"epoch":1777105802,"event":"LD59","format":"md","ldjam_node_id":432038,"likes":1,"metadata":{"p_key":"96694","p_author":"II-P","p_authorkey":"1425409","p_urlkey":"312340","p_title":"Power of wrappers in Unity (ig)","p_cat":"LDJam ","p_event":"LD59","p_time":"1777105802","p_likes":"1","p_comments":"0","p_status":"WAYBACK","us_key":"1425409","us_name":"II-P","us_username":"ii-p","event_start":"1776470400","event_key":"113","event_name":"Ludum Dare 59"},"node":{"_collation":{"body_sanitizer":"TextUtils::SanitizeHTML via existing importer","event":"LD59","removed_author":false},"_superparent":424249,"_trust":1,"author":425409,"body":"Have you ever tried to serialize a matrix in the Unity Inspector or other complex data structures? Initially, Unity will not serialize fields like `List<List<T>>` unless we use a wrapper!\n\nThat\u2019s the key idea: we don\u2019t serialize `List<List<T>>` directly. Instead, we create a brand new serializable class with a property like `List<T> values`, and then serialize `List<WrapperClass>` instead!  \n  \n**Example:**  \nOur wrapper class:\n```csharp\n[Serializable]\npublic class ListOfStrWrapper\n{\n    [TextArea(3, 7)]\n    public List<string> values = new List<string>();\n}\n```\n\nand the fields in another object:\n\n```csharp\npublic List<ListOfStrWrapper> listOfStrWrappers = new List<ListOfStrWrapper>();\n\npublic List<List<string>> listOfListOfStrNoWrapper = new List<List<string>>();\n```\n\n![listwrapper.png](\/\/\/raw\/1cd\/76\/z\/72a96.png)\n\nIt's might be not very clear, but our second structure hasn't serialized!\n\n## But what is the actual use of it?\n\nI came up with this approach to create relatively complex dialogues conveniently and quickly *(very useful for jams! (ig, since I don\u2019t have much experience, haha))*.\n\nIn my project, each single dialogue is represented as a `List<DialogueNode>` *(which is basically a container for the actual text of each node, speaker portrait, their name, etc.)*.\n\nHowever, I need my entities to contain several dialogues, which would mean using `List<List<DialogueNode>>` \u2014 and that is not serializable!\n\nSo, this is exactly where a wrapper becomes useful.\n```csharp\n[Serializable]\npublic class DialogueContainerWrapper\n{\n    public List<DialogueNode> values = new List<DialogueNode>();\n}\n```\nand create `List<DialogueContainerWrapper>` instead!\n**Result:**  \n![dialogueWrapper.png](\/\/\/raw\/1cd\/76\/z\/72a98.png)  \n**And dialogue example:**  \n![wrapper dialogue.gif](\/\/\/raw\/1cd\/76\/z\/72a99.gif)  \n## Pros and Cons\n\n**Pros:** Fast, easy, and convenient for small data structures!\n\n**Cons:** It may become messy when working with grotesque objects and containers. It is fine for around 10 objects with a small number of attributes, but as that number grows, things can get very inconviniet.\n\nFor bigger containers, it would be better to create a ScriptableObject container and assign a list of them instead, or load them from resources.\n\n*Hope you found this small article useful! I\u2019m still learning the engine, and advice from more experienced people would be greatly appreciated, haha!*\n\n**[My very first jam entry](https:\/\/ldjam.com\/events\/ludum-dare\/59\/i-must-scream)**\n","comments":0,"created":"2026-04-25T08:19:39Z","files":[],"files-timestamp":0,"id":432038,"love":1,"love-timestamp":"2026-04-25T09:23:46Z","meta":[],"modified":"2026-04-25T09:23:46Z","name":"Power of wrappers in Unity (ig)","node-timestamp":"2026-04-25T08:33:29Z","parent":425410,"parents":[1,5,9,424249,425410],"path":"\/events\/ludum-dare\/59\/i-must-scream\/power-of-wrappers-in-unity-ig","published":"2026-04-25T08:30:02Z","scope":"public","slug":"power-of-wrappers-in-unity-ig","subsubtype":"","subtype":"","type":"post","version":1372038},"node_metadata":{"n_key":"432038","n_urlkey":"312340","n_parent":"425410","n_path":"\/events\/ludum-dare\/59\/i-must-scream\/power-of-wrappers-in-unity-ig","n_slug":"power-of-wrappers-in-unity-ig","n_type":"post","n_subtype":"","n_subsubtype":"","n_author":"425409","n_created":"1777105179","n_modified":"1777109026","n_version":"1372038","n_status":"WAYBACK"},"source_url":"https:\/\/ldjam.com\/events\/ludum-dare\/59\/i-must-scream\/power-of-wrappers-in-unity-ig","text":"Have you ever tried to serialize a matrix in the Unity Inspector or other complex data structures? Initially, Unity will not serialize fields like `List<List<T>>` unless we use a wrapper!\n\nThat\u2019s the key idea: we don\u2019t serialize `List<List<T>>` directly. Instead, we create a brand new serializable class with a property like `List<T> values`, and then serialize `List<WrapperClass>` instead!  \n  \n**Example:**  \nOur wrapper class:\n```csharp\n[Serializable]\npublic class ListOfStrWrapper\n{\n    [TextArea(3, 7)]\n    public List<string> values = new List<string>();\n}\n```\n\nand the fields in another object:\n\n```csharp\npublic List<ListOfStrWrapper> listOfStrWrappers = new List<ListOfStrWrapper>();\n\npublic List<List<string>> listOfListOfStrNoWrapper = new List<List<string>>();\n```\n\n![listwrapper.png](\/\/\/raw\/1cd\/76\/z\/72a96.png)\n\nIt's might be not very clear, but our second structure hasn't serialized!\n\n## But what is the actual use of it?\n\nI came up with this approach to create relatively complex dialogues conveniently and quickly *(very useful for jams! (ig, since I don\u2019t have much experience, haha))*.\n\nIn my project, each single dialogue is represented as a `List<DialogueNode>` *(which is basically a container for the actual text of each node, speaker portrait, their name, etc.)*.\n\nHowever, I need my entities to contain several dialogues, which would mean using `List<List<DialogueNode>>` \u2014 and that is not serializable!\n\nSo, this is exactly where a wrapper becomes useful.\n```csharp\n[Serializable]\npublic class DialogueContainerWrapper\n{\n    public List<DialogueNode> values = new List<DialogueNode>();\n}\n```\nand create `List<DialogueContainerWrapper>` instead!\n**Result:**  \n![dialogueWrapper.png](\/\/\/raw\/1cd\/76\/z\/72a98.png)  \n**And dialogue example:**  \n![wrapper dialogue.gif](\/\/\/raw\/1cd\/76\/z\/72a99.gif)  \n## Pros and Cons\n\n**Pros:** Fast, easy, and convenient for small data structures!\n\n**Cons:** It may become messy when working with grotesque objects and containers. It is fine for around 10 objects with a small number of attributes, but as that number grows, things can get very inconviniet.\n\nFor bigger containers, it would be better to create a ScriptableObject container and assign a list of them instead, or load them from resources.\n\n*Hope you found this small article useful! I\u2019m still learning the engine, and advice from more experienced people would be greatly appreciated, haha!*\n\n**[My very first jam entry](https:\/\/ldjam.com\/events\/ludum-dare\/59\/i-must-scream)**\n","title":"Power of wrappers in Unity (ig)","wayback_source":[]}