Decentraland Unity Renderer
This repository contains the reference implementation of the decentraland explorer. It includes two main big components, located in the folders:
unity-renderer
which contains the main 3D experience and UIbrowser-interface
to connect to the different aspects requiring of a web browser, such as connection with a wallet and WebRTC communications
Running the Explorer
Main Dependencies
-
Install images and binary files using
git lfs
(git-lfs.github.com). These can be installed from bash or PowerShell by typing:git lfs install git lfs pull
-
The Unity engine and IDE, currently using version 2021.3.14f1
-
node.js, version 16 or later
Steps
Check: Multiplatform in Editor
- Download and install Unity 2021.3.14f1
- Open the scene named
InitialScene
- Within the scene, select the
DebugConfig
GameObject. - On
DebugConfig
inspector, make sure thatBase url mode
is set toCustom
andBase url custom
is set tohttps://play.decentraland.zone/?
- Run the Initial Scene in the Unity editor
- A browser tab with
explorer
should open automatically and steal your focus, don't close it! Login with your wallet, go back to Unity and explorer should start running on theGame View
. - As you can see,
DebugConfig
has other special options like the starting position, etc. You are welcome to use them as you see fit, but you'll have to close the tab and restart the scene for them to make effect.
Troubleshooting
Missing git lfs extension
If while trying to compile the Unity project you get an error regarding some libraries that can not be added (for instance Newtonsoft Json.NET or Google Protobuf), please execute the following command in the root folder:
git lfs install
git lfs pull
Then, on the Unity editor, click on Assets > Reimport All
Testing your branch using automated builds
To test against a build made on this repository, you can use a link with this format:
https://play.decentraland.zone/?explorer-branch=<branch-name>
Links for Contributors
Advanced debugging scenarios
Running the browser-interface
In order to run browser interface in any platform follow the next instructions
make watch
How to run - Open browser-interface with
Visual Studio Code
- Make sure you have the
devcontainers
extension installed - Make sure Docker Desktop is running
At Visual Studio Code
pressF1
executeReopen in Container
and wait for it to finish.- Go to
Terminal > New Terminal
menu and runmake watch
command.
How to run browser-interface unit tests
- Follow the previous process to run
make watch
- Open
localhost:8080/test
in your browser - Watch the results
Debug with Unity Editor + local Browser Interface
Use this approach when working on any features that need both Browser Interface and Unity modifications, and you need to watch Unity code changes fast without the need of injecting a wasm targeted build in the browser.
When the steps are followed, you will be able to test your changes by just pressing the "Play" button within Unity. This will open a tab running the local Browser Interface build and Unity will connect to it using websocket.
This is the most useful debugging scenario for advanced feature implementation.
Steps
- Make sure you have the proper Unity version up and running
- Make sure you are running browser-interface through
make watch
command onbrowser-interface
path. - Back in unity editor, open the
DebugConfig
component inspector ofInitialScene
- Make sure that the component is setup correctly
- Hit 'Play' button
Debug with browsers + local Unity build
This approach works when your Unity modifications run well in the wasm targeted unity build, but you don't want to wait for the CI to kick in. This is also useful for remote profiling.
When the steps are followed, you will be able to run the local Unity build by going to localhost:3000
without the need of CI.
Steps
- Make sure you have the proper Unity version up and running
- Make sure you are running browser-interface through
make watch
command. - Produce a Unity wasm targeted build using the Build menu.
- When the build finishes, copy all the files inside the resulting
/build
folder (unity.loader.js
is not necessary as we use a modified loader) and paste them insidebrowser-interface/node_modules/@dcl/unity-renderer
. - Run the browser explorer through
localhost:8080&ENABLE_WEB3
. Now, it should use your local Unity build. Don't mind the white screen at the beginning, that's because the website repo is not being used and it's only loading Browser Interface with the build. - If you need a Unity re-build, you can just replace the files and reload the browser without restarting the
make watch
process.
Alternatively you can go through these 2 steps after step 3 and load the build locally using localhost:3000
- Make sure you have the explorer website repository cloned.
- Make sure you have the local website up and running by executing
npm run start:linked
in the cloned repo directory (npm i
first just in case). - When the WebGL build finishes, copy all the files inside the resulting
/build
folder (unity.loader.js
is not necessary as we use a modified loader) and paste them insideexplorer-website/node_modules/@dcl/unity-renderer
. - Access using
localhost:3000
Troubleshooting
MacOS: Missing xcrun
If you get the "missing xcrun" error when trying to run the make watch
command, you should download the latest command line tools for macOS, either by downloading them from https://developer.apple.com/download/more/?=command%20line%20tools or by re-installing XCode
System.ComponentModel.Win32Exception (2): No such file or directory...
MacOS: Build fails throwing If the local WebGL build always fails with the error System.ComponentModel.Win32Exception (2): No such file or directory...
it's because you are missing Python needed version (MacOS 12.3 onwards removes the previously-integrated python installation). So to solve this issue just install this Python version.
Frameworks and Tools
Technical how-to guides and explainers
- How to use Unity visual tests
- How to profile a local Unity build remotely
- How to connect the Editor with play.decentraland.org
- For more advanced topics, don't forget to check out our Architecture Decisions Records (ADR) repository.
- How to create new components for ECS7
- How to modify the Renderer Protocol
- How to use Asset Bundle Converter
Setup CircleCI
Copyright info
This repository is protected with a standard Apache 2 license. See the terms and conditions in the LICENSE file.