Nerd For Tech
Published in

Nerd For Tech

Saving an Object in Unity

Objective: Save a object to the user’s system for later use.

An object stored as a .dat file. Not exactly user-friendly…

The object we’d like to save is a case file. It is made up of a few strings and a photo converted into an array of bytes. (See to learn how to convert a photo to bytes.)

When the user hits the submit button, we’ll save the info they’ve inputted. First we’ll create a new instance of a Case and copy the user’s input to it.

Then we’ll save the case as a file by opening a new BinaryFormatter. We’ll assign the file name and the path where the file will be stored, then append it all with the .dat file extension.

Next we’ll open a FileStream to create the file on the path. Then we’ll serialize the object and save it. Finally, we’ll close the FileStream and log the filepath.

If we follow the path, we can see our file successfully saved!

In the next article, we’ll learn how to upload this file to Amazon Web Services (AWS) so the data can be accessed from almost anywhere!




NFT is an Educational Media House. Our mission is to bring the invaluable knowledge and experiences of experts from all over the world to the novice. To know more about us, visit

Recommended from Medium

Detect SQL Injection Attacks from Text in PHP

Recap of AMA MoonXBT Options with the Production Team

Dive into basics of C++

Spark DataFrame Transformations

Programming Rules

Use Linux Firewalld to Create Safe Zone

A quick way to create README using

Creating Production Artifacts in A Multi-Module Maven Project

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Ryan Sweigart

Ryan Sweigart

An independent Unity Developer.

More from Medium

Hidden Shortcuts to Make Level Design Easier

A Simple Shop System for a Unity 2D Game — Part 3: Game Mechanics

Understanding Math.ceil(), Math.round() and Math.floor()

Hidden Shortcuts to Make Level Design Easier in Unity.