SlideShare a Scribd company logo
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

More Related Content

Viewers also liked

Casual and Social Games with Unity
Casual and Social Games with UnityCasual and Social Games with Unity
Casual and Social Games with Unity
Tadej Gregorcic
 
Unity - Software Design Patterns
Unity - Software Design PatternsUnity - Software Design Patterns
Unity - Software Design Patterns
David Baron
 
[Gstar 2013] Unity Security
[Gstar 2013] Unity Security[Gstar 2013] Unity Security
[Gstar 2013] Unity Security
Seungmin Shin
 
Optimizing Large Scenes in Unity
Optimizing Large Scenes in UnityOptimizing Large Scenes in Unity
Optimizing Large Scenes in Unity
Noam 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 Singapore
QuantInsti
 
Trading system in stock exchange
Trading system in stock exchangeTrading system in stock exchange
Trading system in stock exchange
Sumit 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 charts
Raul 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 operations
László Árvai
 
Unity Internals: Memory and Performance
Unity Internals: Memory and PerformanceUnity Internals: Memory and Performance
Unity Internals: Memory and Performance
DevGAMM 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
 
Google's Dremel
Google's DremelGoogle's Dremel
Google's Dremel
Maria Stylianou
 
How to build a trading system
How to build a trading systemHow to build a trading system
How to build a trading system
FXstreet.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 Spark
Jen 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 Technology
Iosif Itkin
 
GBDTを使ったfeature transformationの適用例
GBDTを使ったfeature transformationの適用例GBDTを使ったfeature transformationの適用例
GBDTを使ったfeature transformationの適用例
Takanori Nakai
 

Viewers also liked (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 to [UniteKorea2013] Serialization in Depth

Intro to unity for as3
Intro to unity for as3Intro to unity for as3
Intro to unity for as3
mrondina
 
RailsAdmin - Overview and Best practices
RailsAdmin - Overview and Best practicesRailsAdmin - Overview and Best practices
RailsAdmin - Overview and Best practices
Benoit Bénézech
 
[UniteKorea2013] Memory profiling in Unity
[UniteKorea2013] Memory profiling in Unity[UniteKorea2013] Memory profiling in Unity
[UniteKorea2013] Memory profiling in Unity
William Hugo Yang
 
Introduction to MVC in iPhone Development
Introduction to MVC in iPhone DevelopmentIntroduction to MVC in iPhone Development
Introduction to MVC in iPhone Development
Vu Tran Lam
 
Object Oriented Concept
Object Oriented ConceptObject Oriented Concept
Object Oriented Concept
D Nayanathara
 
Top 20 Drupal Mistakes newbies make
Top 20 Drupal Mistakes newbies makeTop 20 Drupal Mistakes newbies make
Top 20 Drupal Mistakes newbies make
Iztok Smolic
 
Test driving Azure Search and DocumentDB
Test driving Azure Search and DocumentDBTest driving Azure Search and DocumentDB
Test driving Azure Search and DocumentDB
Andrew 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 arrived
Gil Fink
 
Creating Web Templates for SharePoint 2010
Creating Web Templates for SharePoint 2010Creating Web Templates for SharePoint 2010
Creating Web Templates for SharePoint 2010
Mark 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 Organization
Rick Vugteveen
 
Qt Design Patterns
Qt Design PatternsQt Design Patterns
Qt Design Patterns
Ynon Perek
 
Intro to Angular.JS Directives
Intro to Angular.JS DirectivesIntro to Angular.JS Directives
Intro to Angular.JS Directives
Christian 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 known
Mark Rackley
 
jQuery Mobile Deep Dive
jQuery Mobile Deep DivejQuery Mobile Deep Dive
jQuery Mobile Deep Dive
Troy Miles
 
GraphDb in XPages
GraphDb in XPagesGraphDb in XPages
GraphDb in XPages
Oliver Busse
 
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
dri_ireland
 
Forensic Theming - DrupalCon London
Forensic Theming - DrupalCon LondonForensic Theming - DrupalCon London
Forensic Theming - DrupalCon London
Emma Jane Hogbin Westby
 
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 WatiR
Wesley Chen
 

Similar to [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
 

More from William Hugo Yang

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

More from 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
 

Recently uploaded

Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
Generating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using SmithyGenerating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using Smithy
g2nightmarescribd
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Jeffrey Haguewood
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Product School
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
Alison B. Lowndes
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Inflectra
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
Product School
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
OnBoard
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
Elena Simperl
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
Product School
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Tobias Schneck
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Product School
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Thierry Lestable
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 

Recently uploaded (20)

Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
Generating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using SmithyGenerating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using Smithy
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 

[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