Comment on page
Once you have registered your project with ChainSafe Gaming, you can now begin the process for installing the web3.unity SDK into the Unity3D game engine. We will follow the installation with an example of how to implement a sample web3 login screen.
You will need to have MetaMask installed in order to make web3-enabled games. If you already have MetaMask installed, you can skip this section and navigate to the Downloading The SDK section. If you have not installed a web3 wallet, please visit MetaMask for installation instructions.
In order to install web3.unity into the Unity3D game engine, you must download the
web3.unitypackagefile to your computer.
Once you have downloaded the
web3.unitypackagebundle to your computer, you will need to create a new Unity3D project. In the following example, we will create an empty 3D project with a 3D scene. However, the web3.unity plugin supports all Unity project types.
Now that we have created a new project and have a clean interface to work with, we can import the SDK into our project.
Now that we have a new Unity3D project, we are ready to install the web3.unity SDK package. Dragging the
Assetsdirectory will bring up the dialogue shown on the screen below. Press the
Next, we are going to build out our game scene. We will only add the necessary components to build and connect the SDK to a sample Unity3D scene. The SDK provides a
WebLoginscene that connects your web3 wallet to Unity. The is found in the
Scenesfolder. The file is named
WebLogin. This is going to be the first scene that game developers will use.
The web3.unity SDK is multi-chain. This means that our SDK can connect to many different versions of the Ethereum Virtual Machine (EVM) on various blockchains. This is an important step that is often missed when deploying your project. To adjust the chain your game connects to, you will need to update a
network.jsfile, which can be found in the file path:
network.js. Replace the values below with the
rpcUrlof the EVM blockchain you wish to connect to. You can gather this information from Ancient8 Chain Network Information as needed. The SDK will also detect the network your web3 wallet has selected and will change without you having to configure it.
Now, we are ready to build out our sample project. We will use the
WebLoginscene and the default scene provided by Unity. It's important to have a second scene as the SDK expects there to be a connecting screen. This is found by clicking
Build Settings. You will need to drag & import the
WebLoginscene into the first build index. The
WebLoginscene is found in the
Make sure the
WebLoginscene is in the first index followed by the
SampleScenefound in the scenes folder provided by Unity3D. At this point, we are also going to need to change our platform to WebGL within
Build Settings. Select
WebGLand then press
In order to connect the web3.unity SDK to web3, we are going to need to select the custom template provided by the SDK. On selecting the
Project Settingsand navigating to
Resolution and Presentation, select the
Now, we are ready to build out our project and test it in the browser. This will require us to create a folder for our build. This can be named anything you wish.
Unity provides a built-in webserver for our Web3GL-enabled games. On selecting the
build and runoption, Unity will create a built-out project and launch it in your browser. Selecting the login button will prompt the MetaMask wallet extension to open.
After entering your password and selecting an account, the SDK will automatically navigate you to the
SampleScenewe added to the build index.
You have successfully installed the web3.unity SDK. We look forward to seeing what you build.
Here's a tutorial on the complete web3.unity installation flow: