SlideShare una empresa de Scribd logo
1 de 27
Descargar para leer sin conexión
Serialization In Depth
Tim Cooper
Tuesday, 9 April 13
09/04/2013 Page
Who Am I?
• Developer at Unity
• Used to make games!
• Bioshock 1 / 2
• Responsible for:
• Editor features
• Graphics features
2
Tuesday, 9 April 13
09/04/2013 Page
Topics
• Overview
• How serialization works
• How to serialize
• Classes
• Class References
• ScriptableObject
• Arrays
3
Tuesday, 9 April 13
09/04/2013 Page
Topics
• Working with Assets
• Creating an asset
• Custom GUI for assets
• Using an asset at runtime
• Sub-assets
4
Tuesday, 9 April 13
09/04/2013 Page
Overview
• Why write nicely serializable classes?
• Editor windows will survive assembly reload
• Ability to save data as custom asset files
• Easier the writing your own
• Once you know how it works ;)
5
Tuesday, 9 April 13
09/04/2013 Page
Overview
• When does serialization happen?
• On assembly reload
• Script recompilation
• Enter / exit play mode
• Loading and saving the project / scene
6
Tuesday, 9 April 13
09/04/2013 Page
How serialization works
• Assembly reload
• Pull all data out of managed (mono) land
• Create internal representation of the data on C++ side
• Destroy all memory / information in managed land
• Reload assemblies
• Reserialize the data from c++ into managed
• If your data does not make it into c++ it will go away!
7
Tuesday, 9 April 13
09/04/2013 Page
Serializing Classes
• A simple class will not automatically serialize!
• Unity does not know if the class is meant to serialize or not!
• We can fix this!
8
Tuesday, 9 April 13
09/04/2013 Page
Serializing Classes
• A class needs to be marked up to serialize
• [Serializable]
• Field serialization rules
• public - always serialize
• private / protected - serialize on assembly reload (editor)
• static - never serialize
9
Tuesday, 9 April 13
09/04/2013 Page
Serializing Classes
• Field serialization modifiers
• [SerializeField] - Make private / protected fields serialize
• [NonSerialized] - Never serialize the field
10
Tuesday, 9 April 13
09/04/2013 Page
Serializing Structs
• User structs don’t serialize
• A few built in ones do
• Don’t use them for serialization!
11
Tuesday, 9 April 13
09/04/2013 Page
Serializing Class References
• Normal class references
• Each reference serialized individually
• When you deserialize... you have different members
• Think of them as behaving like structs!
• Use them when you have:
• Data that is references only once
• Nested data
12
Tuesday, 9 April 13
09/04/2013 Page
Serializing ScriptableObject
• Serialize as reference properly!
• Multiple references to this object
• Will resolve properly on deserialization
• Supports some Unity callbacks
• OnEnable, OnDisable, OnDestroy
• Create them with CreateInstance <type> ()
13
Tuesday, 9 April 13
09/04/2013 Page
Serializing ScriptableObject
• Use them when you want data
• That is referenced multiple times
• Shared data
• Needs Unity system callbacks
14
Tuesday, 9 April 13
09/04/2013 Page
Serializing ScriptableObject
• Initialization order
• Instance created
• Fields deserialized into object
• If they exist on the c++ side ;)
• OnEnable() Called
15
Tuesday, 9 April 13
09/04/2013 Page
Serializing ScriptableObject
• To create fields properly inside a SO
• Don’t create them in constructor
• Check if they are null in OnEnable ()
• If not null... then they were deserialized
• if null... create them!
16
Tuesday, 9 April 13
09/04/2013 Page
Hideflags
• Control visibility
• Important if you are NOT saving the asset or holding a reference to it
• i.e editor only data structure referenced by a window
• HideAndDontSave
• No asset / scene root - tells unity to consider this a root object
• Will not get cleaned up on scene load (play mode)
• Destroy using Destroy ()
17
Tuesday, 9 April 13
09/04/2013 Page
Serializing Concrete Arrays
• Works as expected
• No object sheering
• Serialized and deserialized properly
• More complex objects?
18
Tuesday, 9 April 13
09/04/2013 Page
Serializing Base Class Arrays
• Does not work as expected
• Breaks on deserialization
• Object shearing occurs
• How can we serialize more complex hierarchies?
19
Tuesday, 9 April 13
09/04/2013 Page
Serializing General Array
• ScriptableObject Array!
• Serializes as references...
• Will serialize as expected
• Only need to set hideflags on ‘the most root’ object
20
Tuesday, 9 April 13
09/04/2013 Page
Asset Creation
• Design the class you want to be an asset
• Database, Character Info, ect
• Ensure that the ‘root’ is a ScriptableObject
• An asset file is a ScriptableObject
• Create the assed by calling
• AssetDatabase.CreateAsset (object, “location.asset”)
• If is mandatory to use the .asset file extension
21
Tuesday, 9 April 13
09/04/2013 Page
Custom Asset UI
• Your asset is just like a Unity asset!
• You can write custom editors
• [CustomEditor (typeof (YourType))]
• Extend from the EditorClass
• Remember to put in in an editor folder!
22
Tuesday, 9 April 13
09/04/2013 Page
Property Fields
• Delegate drawing to a separate class
• Useful for custom controls
• Can be implicitly linked to a class
• [CustomPropertyDrawer (typeof (MyType))]
• Does not need to be marked up per field
• Can be hooked up via an attribute
• Marked on a per field basis!
23
Tuesday, 9 April 13
09/04/2013 Page
Property Fields
• How?
• [CustomPropertyDrawer (typeof (MyType))]
• Extend PropertyDrawer
• Need a custom height?
• Override GetPropertyHeight ()
• Do your custom drawing
• OnGUI ()
24
Tuesday, 9 April 13
09/04/2013 Page
Using Assets
• Create a reference to the type
• Can be anywhere:
• EditorWindow
• MonoBehaviour
• Connect it to an asset
• Via code of the inspector
• Do game specific things!
25
Tuesday, 9 April 13
09/04/2013 Page
Using Sub-Assets
• ScriptableObjects
• Save each manually... they won’t serialize to file all the way down
• How?
• Add them as children of another asset (AddObjectToAsset)
• By default it will show all assets as sub assets
• Set HideFlags to HideFlags.HideInHierarchy
• Much nicer :)
26
Tuesday, 9 April 13
09/04/2013 Page
Using Sub-Assets
• Use SubAssets for complex data structures
• Where many elements are ScriptableObjects
• Graphs
• Databases
• ect!
27
Tuesday, 9 April 13

Más contenido relacionado

Destacado

Casual and Social Games with Unity
Casual and Social Games with UnityCasual and Social Games with Unity
Casual and Social Games with UnityTadej Gregorcic
 
Unity - Software Design Patterns
Unity - Software Design PatternsUnity - Software Design Patterns
Unity - Software Design PatternsDavid Baron
 
[Gstar 2013] Unity Security
[Gstar 2013] Unity Security[Gstar 2013] Unity Security
[Gstar 2013] Unity SecuritySeungmin Shin
 
Optimizing Large Scenes in Unity
Optimizing Large Scenes in UnityOptimizing Large Scenes in Unity
Optimizing Large Scenes in UnityNoam Gat
 
Drill architecture 20120913
Drill architecture 20120913Drill architecture 20120913
Drill architecture 20120913jasonfrantz
 
Futures Trading Strategies on SGX - India chapter in AFACT in Singapore
Futures Trading Strategies on SGX - India chapter in AFACT in SingaporeFutures Trading Strategies on SGX - India chapter in AFACT in Singapore
Futures Trading Strategies on SGX - India chapter in AFACT in SingaporeQuantInsti
 
Trading system in stock exchange
Trading system in stock exchangeTrading system in stock exchange
Trading system in stock exchangeSumit Behura
 
Mechanical trading system based on renko charts
Mechanical trading system based on renko chartsMechanical trading system based on renko charts
Mechanical trading system based on renko chartsRaul Canessa
 
Application design for MiFID II-compliant operations
Application design for MiFID II-compliant operationsApplication design for MiFID II-compliant operations
Application design for MiFID II-compliant operationsLászló Árvai
 
Unity Internals: Memory and Performance
Unity Internals: Memory and PerformanceUnity Internals: Memory and Performance
Unity Internals: Memory and PerformanceDevGAMM Conference
 
Technology Edge in Algo Trading: Traditional Vs Automated Trading System Arch...
Technology Edge in Algo Trading: Traditional Vs Automated Trading System Arch...Technology Edge in Algo Trading: Traditional Vs Automated Trading System Arch...
Technology Edge in Algo Trading: Traditional Vs Automated Trading System Arch...QuantInsti
 
How to build a trading system
How to build a trading systemHow to build a trading system
How to build a trading systemFXstreet.com
 
Logical Clocks (Distributed computing)
Logical Clocks (Distributed computing)Logical Clocks (Distributed computing)
Logical Clocks (Distributed computing)Sri Prasanna
 
Low Latency Execution For Apache Spark
Low Latency Execution For Apache SparkLow Latency Execution For Apache Spark
Low Latency Execution For Apache SparkJen Aman
 
Mutual Exclusion Election (Distributed computing)
Mutual Exclusion Election (Distributed computing)Mutual Exclusion Election (Distributed computing)
Mutual Exclusion Election (Distributed computing)Sri Prasanna
 
EXTENT-2015: MiFID II Projected Impact on Trading Technology
EXTENT-2015: MiFID II Projected Impact on Trading TechnologyEXTENT-2015: MiFID II Projected Impact on Trading Technology
EXTENT-2015: MiFID II Projected Impact on Trading TechnologyIosif Itkin
 
GBDTを使ったfeature transformationの適用例
GBDTを使ったfeature transformationの適用例GBDTを使ったfeature transformationの適用例
GBDTを使ったfeature transformationの適用例Takanori Nakai
 

Destacado (20)

Casual and Social Games with Unity
Casual and Social Games with UnityCasual and Social Games with Unity
Casual and Social Games with Unity
 
Unity - Software Design Patterns
Unity - Software Design PatternsUnity - Software Design Patterns
Unity - Software Design Patterns
 
[Gstar 2013] Unity Security
[Gstar 2013] Unity Security[Gstar 2013] Unity Security
[Gstar 2013] Unity Security
 
Optimizing Large Scenes in Unity
Optimizing Large Scenes in UnityOptimizing Large Scenes in Unity
Optimizing Large Scenes in Unity
 
MapReduceによる大規模データ処理 at Yahoo! JAPAN
MapReduceによる大規模データ処理 at Yahoo! JAPANMapReduceによる大規模データ処理 at Yahoo! JAPAN
MapReduceによる大規模データ処理 at Yahoo! JAPAN
 
Drill architecture 20120913
Drill architecture 20120913Drill architecture 20120913
Drill architecture 20120913
 
Futures Trading Strategies on SGX - India chapter in AFACT in Singapore
Futures Trading Strategies on SGX - India chapter in AFACT in SingaporeFutures Trading Strategies on SGX - India chapter in AFACT in Singapore
Futures Trading Strategies on SGX - India chapter in AFACT in Singapore
 
Trading system in stock exchange
Trading system in stock exchangeTrading system in stock exchange
Trading system in stock exchange
 
Mechanical trading system based on renko charts
Mechanical trading system based on renko chartsMechanical trading system based on renko charts
Mechanical trading system based on renko charts
 
Application design for MiFID II-compliant operations
Application design for MiFID II-compliant operationsApplication design for MiFID II-compliant operations
Application design for MiFID II-compliant operations
 
Unity Internals: Memory and Performance
Unity Internals: Memory and PerformanceUnity Internals: Memory and Performance
Unity Internals: Memory and Performance
 
Technology Edge in Algo Trading: Traditional Vs Automated Trading System Arch...
Technology Edge in Algo Trading: Traditional Vs Automated Trading System Arch...Technology Edge in Algo Trading: Traditional Vs Automated Trading System Arch...
Technology Edge in Algo Trading: Traditional Vs Automated Trading System Arch...
 
Google's Dremel
Google's DremelGoogle's Dremel
Google's Dremel
 
How to build a trading system
How to build a trading systemHow to build a trading system
How to build a trading system
 
Logical Clocks (Distributed computing)
Logical Clocks (Distributed computing)Logical Clocks (Distributed computing)
Logical Clocks (Distributed computing)
 
Low Latency Execution For Apache Spark
Low Latency Execution For Apache SparkLow Latency Execution For Apache Spark
Low Latency Execution For Apache Spark
 
Mutual Exclusion Election (Distributed computing)
Mutual Exclusion Election (Distributed computing)Mutual Exclusion Election (Distributed computing)
Mutual Exclusion Election (Distributed computing)
 
EXTENT-2015: MiFID II Projected Impact on Trading Technology
EXTENT-2015: MiFID II Projected Impact on Trading TechnologyEXTENT-2015: MiFID II Projected Impact on Trading Technology
EXTENT-2015: MiFID II Projected Impact on Trading Technology
 
MapReduce入門
MapReduce入門MapReduce入門
MapReduce入門
 
GBDTを使ったfeature transformationの適用例
GBDTを使ったfeature transformationの適用例GBDTを使ったfeature transformationの適用例
GBDTを使ったfeature transformationの適用例
 

Similar a [UniteKorea2013] Serialization in Depth

Intro to unity for as3
Intro to unity for as3Intro to unity for as3
Intro to unity for as3mrondina
 
RailsAdmin - Overview and Best practices
RailsAdmin - Overview and Best practicesRailsAdmin - Overview and Best practices
RailsAdmin - Overview and Best practicesBenoit Bénézech
 
[UniteKorea2013] Memory profiling in Unity
[UniteKorea2013] Memory profiling in Unity[UniteKorea2013] Memory profiling in Unity
[UniteKorea2013] Memory profiling in UnityWilliam Hugo Yang
 
Introduction to MVC in iPhone Development
Introduction to MVC in iPhone DevelopmentIntroduction to MVC in iPhone Development
Introduction to MVC in iPhone DevelopmentVu Tran Lam
 
Object Oriented Concept
Object Oriented ConceptObject Oriented Concept
Object Oriented ConceptD Nayanathara
 
Top 20 Drupal Mistakes newbies make
Top 20 Drupal Mistakes newbies makeTop 20 Drupal Mistakes newbies make
Top 20 Drupal Mistakes newbies makeIztok Smolic
 
Test driving Azure Search and DocumentDB
Test driving Azure Search and DocumentDBTest driving Azure Search and DocumentDB
Test driving Azure Search and DocumentDBAndrew Siemer
 
Stencil the time for vanilla web components has arrived
Stencil the time for vanilla web components has arrivedStencil the time for vanilla web components has arrived
Stencil the time for vanilla web components has arrivedGil Fink
 
Creating Web Templates for SharePoint 2010
Creating Web Templates for SharePoint 2010Creating Web Templates for SharePoint 2010
Creating Web Templates for SharePoint 2010Mark Collins
 
Scriptable Objects in Unity Game Engine (C#)
Scriptable Objects in Unity Game Engine (C#)Scriptable Objects in Unity Game Engine (C#)
Scriptable Objects in Unity Game Engine (C#)Om Shridhar
 
Off the Treadmill: Building a Drupal Platform for Your Organization
Off the Treadmill: Building a Drupal Platform for Your OrganizationOff the Treadmill: Building a Drupal Platform for Your Organization
Off the Treadmill: Building a Drupal Platform for Your OrganizationRick Vugteveen
 
Qt Design Patterns
Qt Design PatternsQt Design Patterns
Qt Design PatternsYnon Perek
 
Intro to Angular.JS Directives
Intro to Angular.JS DirectivesIntro to Angular.JS Directives
Intro to Angular.JS DirectivesChristian Lilley
 
SPSDenver - SharePoint & jQuery - What I wish I would have known
SPSDenver - SharePoint & jQuery - What I wish I would have knownSPSDenver - SharePoint & jQuery - What I wish I would have known
SPSDenver - SharePoint & jQuery - What I wish I would have knownMark Rackley
 
jQuery Mobile Deep Dive
jQuery Mobile Deep DivejQuery Mobile Deep Dive
jQuery Mobile Deep DiveTroy Miles
 
Kevin Long - Preparing your collection for DRI
Kevin Long - Preparing your collection for DRIKevin Long - Preparing your collection for DRI
Kevin Long - Preparing your collection for DRIdri_ireland
 
Views Mini-Course, Part III: How to Back Up Your Views Safely
Views Mini-Course, Part III: How to Back Up Your Views SafelyViews Mini-Course, Part III: How to Back Up Your Views Safely
Views Mini-Course, Part III: How to Back Up Your Views SafelyAcquia
 
What you can do In WatiR
What you can do In WatiRWhat you can do In WatiR
What you can do In WatiRWesley Chen
 

Similar a [UniteKorea2013] Serialization in Depth (20)

Intro to unity for as3
Intro to unity for as3Intro to unity for as3
Intro to unity for as3
 
RailsAdmin - Overview and Best practices
RailsAdmin - Overview and Best practicesRailsAdmin - Overview and Best practices
RailsAdmin - Overview and Best practices
 
[UniteKorea2013] Memory profiling in Unity
[UniteKorea2013] Memory profiling in Unity[UniteKorea2013] Memory profiling in Unity
[UniteKorea2013] Memory profiling in Unity
 
Introduction to MVC in iPhone Development
Introduction to MVC in iPhone DevelopmentIntroduction to MVC in iPhone Development
Introduction to MVC in iPhone Development
 
Object Oriented Concept
Object Oriented ConceptObject Oriented Concept
Object Oriented Concept
 
Top 20 Drupal Mistakes newbies make
Top 20 Drupal Mistakes newbies makeTop 20 Drupal Mistakes newbies make
Top 20 Drupal Mistakes newbies make
 
Test driving Azure Search and DocumentDB
Test driving Azure Search and DocumentDBTest driving Azure Search and DocumentDB
Test driving Azure Search and DocumentDB
 
Stencil the time for vanilla web components has arrived
Stencil the time for vanilla web components has arrivedStencil the time for vanilla web components has arrived
Stencil the time for vanilla web components has arrived
 
Creating Web Templates for SharePoint 2010
Creating Web Templates for SharePoint 2010Creating Web Templates for SharePoint 2010
Creating Web Templates for SharePoint 2010
 
Scriptable Objects in Unity Game Engine (C#)
Scriptable Objects in Unity Game Engine (C#)Scriptable Objects in Unity Game Engine (C#)
Scriptable Objects in Unity Game Engine (C#)
 
Off the Treadmill: Building a Drupal Platform for Your Organization
Off the Treadmill: Building a Drupal Platform for Your OrganizationOff the Treadmill: Building a Drupal Platform for Your Organization
Off the Treadmill: Building a Drupal Platform for Your Organization
 
Qt Design Patterns
Qt Design PatternsQt Design Patterns
Qt Design Patterns
 
Intro to Angular.JS Directives
Intro to Angular.JS DirectivesIntro to Angular.JS Directives
Intro to Angular.JS Directives
 
SPSDenver - SharePoint & jQuery - What I wish I would have known
SPSDenver - SharePoint & jQuery - What I wish I would have knownSPSDenver - SharePoint & jQuery - What I wish I would have known
SPSDenver - SharePoint & jQuery - What I wish I would have known
 
jQuery Mobile Deep Dive
jQuery Mobile Deep DivejQuery Mobile Deep Dive
jQuery Mobile Deep Dive
 
GraphDb in XPages
GraphDb in XPagesGraphDb in XPages
GraphDb in XPages
 
Kevin Long - Preparing your collection for DRI
Kevin Long - Preparing your collection for DRIKevin Long - Preparing your collection for DRI
Kevin Long - Preparing your collection for DRI
 
Forensic Theming - DrupalCon London
Forensic Theming - DrupalCon LondonForensic Theming - DrupalCon London
Forensic Theming - DrupalCon London
 
Views Mini-Course, Part III: How to Back Up Your Views Safely
Views Mini-Course, Part III: How to Back Up Your Views SafelyViews Mini-Course, Part III: How to Back Up Your Views Safely
Views Mini-Course, Part III: How to Back Up Your Views Safely
 
What you can do In WatiR
What you can do In WatiRWhat you can do In WatiR
What you can do In WatiR
 

Más de William Hugo Yang

[UniteKorea2013] Protecting your Android content
[UniteKorea2013] Protecting your Android content[UniteKorea2013] Protecting your Android content
[UniteKorea2013] Protecting your Android contentWilliam Hugo Yang
 
[UniteKorea2013] Unity Hacks
[UniteKorea2013] Unity Hacks[UniteKorea2013] Unity Hacks
[UniteKorea2013] Unity HacksWilliam Hugo Yang
 
[UniteKorea2013] Butterfly Effect DX11
[UniteKorea2013] Butterfly Effect DX11[UniteKorea2013] Butterfly Effect DX11
[UniteKorea2013] Butterfly Effect DX11William Hugo Yang
 
[UniteKorea2013] The Unity Rendering Pipeline
[UniteKorea2013] The Unity Rendering Pipeline[UniteKorea2013] The Unity Rendering Pipeline
[UniteKorea2013] The Unity Rendering PipelineWilliam Hugo Yang
 
[UniteKorea2013] Art tips and tricks
[UniteKorea2013] Art tips and tricks[UniteKorea2013] Art tips and tricks
[UniteKorea2013] Art tips and tricksWilliam Hugo Yang
 
[UniteKorea2013] 2D content workflows
[UniteKorea2013] 2D content workflows[UniteKorea2013] 2D content workflows
[UniteKorea2013] 2D content workflowsWilliam Hugo Yang
 

Más de William Hugo Yang (6)

[UniteKorea2013] Protecting your Android content
[UniteKorea2013] Protecting your Android content[UniteKorea2013] Protecting your Android content
[UniteKorea2013] Protecting your Android content
 
[UniteKorea2013] Unity Hacks
[UniteKorea2013] Unity Hacks[UniteKorea2013] Unity Hacks
[UniteKorea2013] Unity Hacks
 
[UniteKorea2013] Butterfly Effect DX11
[UniteKorea2013] Butterfly Effect DX11[UniteKorea2013] Butterfly Effect DX11
[UniteKorea2013] Butterfly Effect DX11
 
[UniteKorea2013] The Unity Rendering Pipeline
[UniteKorea2013] The Unity Rendering Pipeline[UniteKorea2013] The Unity Rendering Pipeline
[UniteKorea2013] The Unity Rendering Pipeline
 
[UniteKorea2013] Art tips and tricks
[UniteKorea2013] Art tips and tricks[UniteKorea2013] Art tips and tricks
[UniteKorea2013] Art tips and tricks
 
[UniteKorea2013] 2D content workflows
[UniteKorea2013] 2D content workflows[UniteKorea2013] 2D content workflows
[UniteKorea2013] 2D content workflows
 

Último

Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesZilliz
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfSeasiaInfotech2
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 

Último (20)

Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector Databases
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdf
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 

[UniteKorea2013] Serialization in Depth

  • 1. Serialization In Depth Tim Cooper Tuesday, 9 April 13
  • 2. 09/04/2013 Page Who Am I? • Developer at Unity • Used to make games! • Bioshock 1 / 2 • Responsible for: • Editor features • Graphics features 2 Tuesday, 9 April 13
  • 3. 09/04/2013 Page Topics • Overview • How serialization works • How to serialize • Classes • Class References • ScriptableObject • Arrays 3 Tuesday, 9 April 13
  • 4. 09/04/2013 Page Topics • Working with Assets • Creating an asset • Custom GUI for assets • Using an asset at runtime • Sub-assets 4 Tuesday, 9 April 13
  • 5. 09/04/2013 Page Overview • Why write nicely serializable classes? • Editor windows will survive assembly reload • Ability to save data as custom asset files • Easier the writing your own • Once you know how it works ;) 5 Tuesday, 9 April 13
  • 6. 09/04/2013 Page Overview • When does serialization happen? • On assembly reload • Script recompilation • Enter / exit play mode • Loading and saving the project / scene 6 Tuesday, 9 April 13
  • 7. 09/04/2013 Page How serialization works • Assembly reload • Pull all data out of managed (mono) land • Create internal representation of the data on C++ side • Destroy all memory / information in managed land • Reload assemblies • Reserialize the data from c++ into managed • If your data does not make it into c++ it will go away! 7 Tuesday, 9 April 13
  • 8. 09/04/2013 Page Serializing Classes • A simple class will not automatically serialize! • Unity does not know if the class is meant to serialize or not! • We can fix this! 8 Tuesday, 9 April 13
  • 9. 09/04/2013 Page Serializing Classes • A class needs to be marked up to serialize • [Serializable] • Field serialization rules • public - always serialize • private / protected - serialize on assembly reload (editor) • static - never serialize 9 Tuesday, 9 April 13
  • 10. 09/04/2013 Page Serializing Classes • Field serialization modifiers • [SerializeField] - Make private / protected fields serialize • [NonSerialized] - Never serialize the field 10 Tuesday, 9 April 13
  • 11. 09/04/2013 Page Serializing Structs • User structs don’t serialize • A few built in ones do • Don’t use them for serialization! 11 Tuesday, 9 April 13
  • 12. 09/04/2013 Page Serializing Class References • Normal class references • Each reference serialized individually • When you deserialize... you have different members • Think of them as behaving like structs! • Use them when you have: • Data that is references only once • Nested data 12 Tuesday, 9 April 13
  • 13. 09/04/2013 Page Serializing ScriptableObject • Serialize as reference properly! • Multiple references to this object • Will resolve properly on deserialization • Supports some Unity callbacks • OnEnable, OnDisable, OnDestroy • Create them with CreateInstance <type> () 13 Tuesday, 9 April 13
  • 14. 09/04/2013 Page Serializing ScriptableObject • Use them when you want data • That is referenced multiple times • Shared data • Needs Unity system callbacks 14 Tuesday, 9 April 13
  • 15. 09/04/2013 Page Serializing ScriptableObject • Initialization order • Instance created • Fields deserialized into object • If they exist on the c++ side ;) • OnEnable() Called 15 Tuesday, 9 April 13
  • 16. 09/04/2013 Page Serializing ScriptableObject • To create fields properly inside a SO • Don’t create them in constructor • Check if they are null in OnEnable () • If not null... then they were deserialized • if null... create them! 16 Tuesday, 9 April 13
  • 17. 09/04/2013 Page Hideflags • Control visibility • Important if you are NOT saving the asset or holding a reference to it • i.e editor only data structure referenced by a window • HideAndDontSave • No asset / scene root - tells unity to consider this a root object • Will not get cleaned up on scene load (play mode) • Destroy using Destroy () 17 Tuesday, 9 April 13
  • 18. 09/04/2013 Page Serializing Concrete Arrays • Works as expected • No object sheering • Serialized and deserialized properly • More complex objects? 18 Tuesday, 9 April 13
  • 19. 09/04/2013 Page Serializing Base Class Arrays • Does not work as expected • Breaks on deserialization • Object shearing occurs • How can we serialize more complex hierarchies? 19 Tuesday, 9 April 13
  • 20. 09/04/2013 Page Serializing General Array • ScriptableObject Array! • Serializes as references... • Will serialize as expected • Only need to set hideflags on ‘the most root’ object 20 Tuesday, 9 April 13
  • 21. 09/04/2013 Page Asset Creation • Design the class you want to be an asset • Database, Character Info, ect • Ensure that the ‘root’ is a ScriptableObject • An asset file is a ScriptableObject • Create the assed by calling • AssetDatabase.CreateAsset (object, “location.asset”) • If is mandatory to use the .asset file extension 21 Tuesday, 9 April 13
  • 22. 09/04/2013 Page Custom Asset UI • Your asset is just like a Unity asset! • You can write custom editors • [CustomEditor (typeof (YourType))] • Extend from the EditorClass • Remember to put in in an editor folder! 22 Tuesday, 9 April 13
  • 23. 09/04/2013 Page Property Fields • Delegate drawing to a separate class • Useful for custom controls • Can be implicitly linked to a class • [CustomPropertyDrawer (typeof (MyType))] • Does not need to be marked up per field • Can be hooked up via an attribute • Marked on a per field basis! 23 Tuesday, 9 April 13
  • 24. 09/04/2013 Page Property Fields • How? • [CustomPropertyDrawer (typeof (MyType))] • Extend PropertyDrawer • Need a custom height? • Override GetPropertyHeight () • Do your custom drawing • OnGUI () 24 Tuesday, 9 April 13
  • 25. 09/04/2013 Page Using Assets • Create a reference to the type • Can be anywhere: • EditorWindow • MonoBehaviour • Connect it to an asset • Via code of the inspector • Do game specific things! 25 Tuesday, 9 April 13
  • 26. 09/04/2013 Page Using Sub-Assets • ScriptableObjects • Save each manually... they won’t serialize to file all the way down • How? • Add them as children of another asset (AddObjectToAsset) • By default it will show all assets as sub assets • Set HideFlags to HideFlags.HideInHierarchy • Much nicer :) 26 Tuesday, 9 April 13
  • 27. 09/04/2013 Page Using Sub-Assets • Use SubAssets for complex data structures • Where many elements are ScriptableObjects • Graphs • Databases • ect! 27 Tuesday, 9 April 13