Anyone can create a metaverse game; however, building it correctly with working elements is something many fail to do, especially when they use primitive and outdated tools. Thus, the trick to building a fully functional metaverse game and doing so quickly lies in using the proper tools. With Moralis, you can easily complete our “how to build a metaverse game” example project in about 25 minutes. Also, while many think blockchain development seems daunting, Moralis simplifies the process. With that said, we will not only show you how to build a metaverse game quickly herein but also show you how to build one the right way.
Moving forward, you’ll learn how to build a metaverse game with the pinnacle of the current Web3 tech stack – Moralis. This “Firebase for crypto” tool is the ultimate Web3 development platform that takes care of the entire backend. Furthermore, Moralis’ Metaverse SDK enables you to use Unity to deliver phenomenal blockchain games. As such, you can start exploiting Unity Web3 opportunities. The latter include GameFi and play-to-earn (P2E), which are important features of the metaverse. Moreover, with the best Web3 backend platform, you get to devote your attention and resources to creating the best possible Web3 UI. Hence, you get to offer your users what they want without any overhead of dealing with the backend. Nonetheless, with Unity and Moralis, our “how to build a metaverse game” quest boils down to three major steps. These include creating a 3D world, creating an avatar, and adding Web3 authentication.
How to Build a Metaverse Game – Example Project
As mentioned, this article will address our “how to build a metaverse game” example project. In the upcoming sections, we’ll cover all the necessary steps, including the initial setup. Along the way, you’ll learn about several valuable shortcuts. For one, we’ll use the asset store from Unity to acquire ready-to-use in-game elements. As such, we’ll use these elements to build our example 3D space and our example character in minutes. In addition, we decided to make this quest even simpler for you by making our code available on GitHub. However, before we start building our metaverse, let’s do a quick demo of our finished example dapp (decentralized application).
How to Build a Metaverse Game with Unity – Demo
Let’s start by taking a glance at what our potential users will see when using our metaverse game:
As you can see in the screenshot above, users have a chance to use a neat Web3 login method. By scanning the QR code, which serves as a gateway to our metaverse, they get to control the avatar. Moreover, as you can see, the avatar is located in a medieval library. The latter is an example of our 3D world. Also, above the code is a clear instruction message that tells users how to get started. In addition, the users’ Web3 wallet addresses will be displayed above the character’s head:
Furthermore, you can see that our example metaverse game contains all the basics, including user-friendly Web3 authentication, a 3D world, and an avatar. Hence, it’s sort of a Web3 RPG game. Moreover, we also kept things relatively simple so that you’ll be able to cover everything in less than 30 minutes. The point of this example is to get your ideas flowing by seeing the potential that is at your disposal. For instance, you can expand this 3D world by adding rooms, buildings, or even maps. In addition, you can add additional characters. Thus, you can create a proper metaverse or at least a Web3 MMORPG with ease. Now that you have the end in mind, it’s time to show you how to build a metaverse game with Unity and Moralis.
Note: At the bottom of this article, you can also view this demo in video format (0:51).
How to Build a Metaverse Game with Unity and Moralis
As was mentioned earlier in this article, we can complete the “how to build a metaverse game” challenge in three main steps:
- Creating a 3D world.
- Adding a third-person character (an avatar).
- Incorporating a Web3 wallet login using a neat QR code option.
We will complete the first two steps using the Unity engine in combination with free assets available in Unity’s Asset Store.
Note: All assets we used in our metaverse game example await you in the “Assets” folder on GitHub.
As you might have noticed, the first two steps have nothing to do with Web3. In fact, it is the third step that will convert our example project into Web3 to complete our “build a metaverse game” quest. This is where you’ll see the power of Moralis and how it solves our blockchain-related backend needs. Moreover, since Web3 authentication is an essential part of all dapps, this is what we’ll focus on herein. Furthermore, with various solid login options available, it is important to know what will best work for your users. For example, in case your users are crypto-savvy folks, MetaMask and WalletConnect authentications are the best alternatives. On the other hand, if you are targeting Web3 newcomers, Web3 authentication via email and Web3 social login are even better options. Hence, it is important to consider who you are targeting with your metaverse game.
Save Time and Resources when Building Metaverse Games
Fortunately, Moralis’ SDK offers you all of the above-mentioned alternatives. Furthermore, with Moralis servers, Moralis dashboard (database), and the Moralis “sync” feature, you get to index the blockchain. Once you sync and index smart contract events, the “sky’s the limit” to what features you want to add to your dapps. Also, it’s thanks to these sorts of shortcuts that Moralis saves developers more than 87% of development time. Nonetheless, you should also note that Moralis is all about cross-chain interoperability. As a result, your dapps and metaverse games can easily be deployed to all supported chains. Hence, your work is also “future-proofed”.
Now it’s time to roll up your sleeves and follow a Moralis expert’s lead. Follow along or watch the video tutorial below as he’ll hold your hand from the beginning to the finish line. Without further ado, let’s start by creating a 3D world presented in the demo above.
Creating a 3D World
To get detailed guidance for this part of our example project, use the video below (3:57). The Moralis expert will show you how to build a metaverse game by starting with a new scene. You will first discover how to properly group and arrange the asset files. By doing so, you’ll be able to easily navigate your folders. As far as creating a 3D world goes, you will rely on the “CustomRoom” file. The latter also includes a sword resting on top of a chest box (both of these elements have been added by the Moralis expert):
Adding a Third-Person Character
At this point, you should have your simple 3D world created. In turn, you are ready to add your avatar. Fortunately, this is also where free assets offer an incredible shortcut. The latter eliminates the need to create characters from scratch. Furthermore, the details covering the creation of your avatar start at 5:30 in the video below. This is where you’ll learn how to locate “NestedParentArmature” (“Player”). Moreover, this file will serve you as a base for your character:
Along the way, you’ll also learn how to add a mesh collider. Then, your 3D room will have a floor on which the character will walk on. Thus, with a “skeleton” avatar and a 3D room with a floor ready, you already have the movement functionality:
However, as you can see in the screenshot above, your avatar still has a robotic appearance. As such, you’ll need to change your avatar’s armature next. As far as this example project goes, we choose the “Male C” option. However, you can use any other option. By choosing an avatar armature and completing some simple setups (details in the video below), you will end up with a proper avatar:
Incorporating Web3 Functionality
Starting at 8:25 (video below), you’ll see how to easily access the Moralis Metaverse SDK using a quick Google search. Although, you can just use the “Moralis Metaverse SDK” mentioned at the beginning of the article. After landing on the Moralis Metaverse SDK page, you’ll need to scroll down until you see the “Start Now” button:
By clicking on the above button, you’ll be taken to the Ethereum Unity boilerplate on GitHub. There, you need to select the “Releases” section to get the latest version:
Next, download the top file “.unitypackage”:
Now, you need to use Unity to open the above-downloaded folder. The simplest way to do this is to drag and drop that folder into Unity’s interface. Also, don’t forget to confirm the import. As such, you’ll be able to access the content of the “MoralisWeb3ApiSdk” folder in Unity:
There are a lot of useful folders and files inside that folder. However, for the sake of this example project, we’ll only use “MoralisSetup” and “WalletConnect”. As such, find these two components using the search bar and drag and drop each of them to your “Hierarchy” tab:
After adding these two components, you need to tweak some settings. As far as the WalletConnect component goes, use the video at 10:00. For the “MoralisSetup” component, you need to jump over to 10:17. Moreover, inside the “MoralisSetup” prefab, you’ll need your Moralis server’s details:
Initial Moralis Setup – Obtaining Server Details and Connecting Unity with Moralis’ SDK
If you want to learn how to build a metaverse game with Unity and Moralis, you need to complete some simple initial Moralis setup steps. For starters, you need to create your Moralis server (10:41). Fortunately, this is pretty straightforward:
- Log In to Your Moralis Account – In case you don’t have a Moralis account yet, create your free Moralis account.
- Create a Moralis Server – Inside your Moralis admin area, click on the “+ Create a new Server” button and complete the following steps:
- Select the server type:
- Enter your server details:
- Access Your Server’s Details – With your server up and running, you get to access its details:
- Copy your server’s URL and application ID:
- Populate Unity – Paste the above-copied details into the appropriate fields inside Unity:
Initial Moralis Setup – Using Speedy Nodes
The second part of the initial Moralis setup revolves around Moralis Speedy Nodes (11:24). As you can see in the screenshot above, you need your speedy node’s URL. Fortunately, with your Moralis account, you already have access to this product from Moralis. So, navigate to the “Speedy Nodes” tab inside your Moralis admin area. Next, select the “Endpoints” button under the corresponding network:
Next, copy the mainnet or testnet URL address:
Finally, go back to Unity and paste that URL address into the entry field next to the “Web 3 Rpc Node Url”:
At 11:50 of the video below, you’ll see exactly how to link WalletConnect. Now, with the above setup completed, you can move on to the final touches of our example metaverse game. If you recall our demo, you’ll notice that we still haven’t added the QR code. Thus, make sure to follow along with the Moralis expert, starting at 11:56. Furthermore, starting at 13:47, you will also learn how to display users’ addresses above the avatar. Nonetheless, you’ll also have a chance to take a closer look at the code script behind the scenes (15:00).
Here’s the video tutorial that we’ve been referencing throughout the article:
How to Build a Metaverse Game in 25 Minutes – Summary
By covering the above sections, you’ve learned how to build a metaverse game in less than half an hour. Also, if you’ve rolled up your sleeves and followed our instructions, you’ve also created your own version of a simple metaverse game. Essentially, you’ve built a simple medieval metaverse game. Along the way, you’ve learned how to complete the initial Moralis setup and how to connect Unity with Moralis’ SDK. Furthermore, you’ve discovered how publicly available Unity assets can serve as a shortcut. Nonetheless, you’ve completed the implementation of Web3 authentication. Hence, you are ready to take your metaverse development further. As such, we recommend you learn to communicate with a Web3 database from Unity, how to store off-chain data, and how to do blockchain game transactions with Unity.
However, in case you want to explore other blockchain development topics, make sure to visit the Moralis YouTube channel and the Moralis blog. Both of these outlets offer a ton of valuable content and can serve as reliable and free crypto education sources. Some of the latest topics explore how to reduce Solidity gas costs, how to create an Ethereum NFT, how to build a 2D Web3 game, how to create a GameFi game, how OpenSea trades NFTs without gas fees, and much more. Although, if you are eager to get into Web3 in a more professional manner, consider enrolling in Moralis Academy. There, you’ll get access to top-tier crypto development courses, an excellent community, and professional mentors.