Unity and Ethereum: Why and How

Ethereum has great potential for gaming. In this tutorial you will learn why Ethereum is interesting for you as a game developer. By Kevin Small.

4 (4) · 1 Review

Download materials
Save for later
Share

You know about Bitcoin, but do you know about its relative, Ethereum, and the potential it offers for gaming?

In this tutorial, you’ll learn why Ethereum is interesting for game developers and how it works from a game developer’s perspective.

By the end of this tutorial, you’ll know:

  • Why the Ethereum network can disrupt the game industry.
  • How the Ethereum network works at a high level, and how you can interact with it.
  • How a Unity game connects to the Ethereum network using the Nethereum library. You’ll see a demo project store and retrieve high-scores from an Ethereum test network.
Note: This tutorial assumes you’re familiar with Unity, and that you have an intermediate knowledge of C#. If you need need some refreshers, check out our other Unity tutorials. Prior knowledge of Ethereum is unnecessary.

Time to get started!

Why Ethereum Is Interesting

So why should you, as a game developer, care about Ethereum? To understand, you need to consider the game ecosystem. In other words, you need to think about how you play games today and how your data is stored.

The Game Ecosystem Today

Ethereum and Unity: Why and How

When you play a game, you generate all types of data. This data includes game progress, achievements, friends lists, items and many other things. Third parties like PlayStation Network, Xbox Live, Steam and many others store this data for you. This data is about you, but you don’t own it. In most cases, the only way to access this data is on the terms and conditions set down by the third party providers. You must also trust, or rather hope, that these same providers don’t get hacked or close up shop, which happens more often than you may realize – especially once they become profitable.

The Game Ecosystem With Ethereum

Ethereum and Unity: Why and How 

The Ethereum network, on the other hand, requires no third party to run or oversee it, and it’s incredibly secure. Also, by storing your gameplay data in Ethereum, you can reclaim ownership of your data.

However, Ethereum isn’t free. Without third parties paying for the costs, gamers will need to pay small fees to the Ethereum network to store their data. Once you understand what Ethereum can offer, you’ll agree this isn’t such a bad deal.

Opportunities In The Game Ecosystem With Ethereum

Ethereum and Unity: Why and How 

Once your gameplay data is in Ethereum and controlled by you, fantastic opportunities arise. Every game, regardless of its platform, has access to your gameplay data. Imagine an Xbox game offering you a free spaceship because you own an item in another game on the PlayStation!

Even more exciting is that, because you own your items, you can trade them for other items across different games and platforms. You can even sell your items for cash without having to get permission from any third party controlling your data (because there is no third party!). Imagine trading that free spaceship with someone for an item they own in another game, on another platform. 

Before learning more about how Ethereum works, you need to get familiar with the demo project.

Starter Project

Download the starter project for this tutorial using the link at the top or bottom of this page.

Open the project in Unity, and open the scene named main, which is located in Assets\RW\Scenes\.

Note: You’ll get some warnings about unassigned fields. For now, you can ignore these; they’ll be gone by the end of the tutorial.

Review the game object hierarchy:

Ethereum and Unity: Why and How 

  • Main Camera: Camera.
  • EventSystem: Handles events and input.
  • GameplayController: All gameplay logic.
  • UI Gameplay: UI for instructions.
  • HighScoreController: All logic relating to high scores and Ethereum. The only editing you’ll do in this tutorial is on the script attached to this GameObject.
  • UI HighScore: UI for the high score timer, scroll view and refresh button.
  • Arena: Gameplay objects.

Press the Play button.

You play as Ether the Elephant. Your goal is to avoid contact with the other animals. The amount of time you avoid them translates to your score.

Looking at the game’s interface, the playing field is on the left; and on the right, there’s an empty high score table and a refresh button that currently does nothing:

screeen01.jpg 

Throughout the rest of this tutorial, you’ll build up the UI items and integrate the game with an Ethereum test network that stores high scores. But first, you must understand how Ethereum works. You also need to get yourself an Ethereum account.

How Ethereum Works

This section explains the Ethereum network and intentionally avoids using technical terms.

Ethereum is young. It first went live in 2015. Its development stage is akin to how the internet was in the early 1990s. Just like the early internet, Ethereum has critics and challenges ahead of it.

Ethereum uses a network of computers linked together over the internet. Each computer is a node. Simple programs run on these nodes, and they are usually written in a language called Solidity. Solidity is a bit like a subset of JavaScript or C#. Learning Solidity is beyond the scope of this tutorial.

The programs run on the nodes inside a virtual machine. A virtual machine is like a standalone operating system that runs inside the main operating system on the node. This virtual machine is an EVM (Ethereum Virtual Machine). The EVM helps to prevent programs from doing bad things like trying to wipe a node’s hard drive. The EVM also provides a standard environment in which programs run. A node might use Windows or Linux as its main operating system, and in either case, will offer the same standardized EVM:

diagram04.jpg 

The programs must be quite simple. They can talk to each other but should not move vast amounts of data or do huge amounts of processing. Suitable candidates are things like recording ownership of assets, voting, auctions or trading. A good rule of thumb is that a program can be about as sophisticated as a good programmable calculator.

The Ethereum network has a “heartbeat” where every 15 seconds or so, all the eligible programs on the network run and the results get stored.