Getting Started with Godot: The Open Source Game Engine
Oculus Developer Blog
|
Posted by Bastiaan Olij
|
August 29, 2019
|
Share

Forward by Eric Cosky, Developer Relations Engineer, Oculus Content
A key goal of the Oculus Content team is to enable the success of our VR developer ecosystem, and sometimes this takes the indirect form of working with those who are building the tools that VR developers use every day. When a great tool that inspires people to create VR content becomes available, everyone wins, so we are always on the lookout for tools and solutions that enable more efficient, successful development.

Today, we are happy to highlight the Godot game engine, an open source project that has been in development for some time and has recently been making rapid advances in their support for VR. The Godot engine provides a rare opportunity to use a collaboratively built, MIT licensed game engine for VR development where you - yes you - can make a real difference in how the engine evolves. If this sounds useful, interesting or just plain fun, please read on as the creators of Godot share why the tool was created, and how you can get started developing VR applications with this open source game engine.


A very brief history of Godot

Godot is the brainchild of Juan ‘Reduz’ Linietsky and Ariel ‘Punto’ Manzur, who have been developing games for decades. In February 2014 the engine was put on GitHub as an Open Source project with a very unrestrictive MIT license. Support for most major VR headsets has been available since early 2018, while the engine now also supports AR. The Oculus Quest is the latest headset in the lineup to get support with the upcoming Godot 3.2 release.

Godot was designed as an OpenGL based engine with modern features such as HDR, PBR materials and Global Illumination. It is currently undergoing a rewrite to use Vulkan which will significantly improve performance on the Quest. It will likely become available around the end of 2019 or early 2020.

Getting started with VR in Godot

One of the goals for the team was to make the move to VR as easy as possible, so let's go through the steps to create a real bare bones VR solution for the Oculus Rift.

To download Godot, simply visit GodotEngine.org. The version currently available is 3.1.1 which for our purpose today is sufficient. You’ll notice there are Windows, Mac OS X and Linux versions available, but as we’ll be building for the Oculus Rift we’ll be using the Windows version. You will also need the 64bit version, the Godot Oculus Rift plugin only supports this architecture.

You also have the choice between the standard version of Godot that uses GDScript, a Python inspired language for scripting, and a version that supports C#. In this exercise we’ll use GDScript so we can avoid the added steps involved to setup the C# environment. However, if you are more comfortable with C# there is helpful documentation on the Godot website and many side by side examples of GDScript and C# in Godot. GDScript itself is a solid choice as the language is deeply integrated in the engine, it is incredibly easy to learn, and there is great documentation for it.

The download is just over 20Mb (I’m not kidding). Unzip the zip file and you will find a single executable inside. That’s all you need. This will open up Godot's project manager. It will detect that you do not have any projects, just cancel out of the dialog.

Press new project, this will open up a dialog that asks for an empty folder in which Godot will create your project files. You will also be able to select between the high definition OpenGL ES 3.0 render pipeline and the simpler OpenGL ES 2.0 pipeline. We’ll stick with the 3.0 option but you can always change this later on. Hit Create & Edit to open up your new project.

At first this interface can be a little daunting, but we’ll walk through the important bits quickly.


Godot works by organizing your game into scenes, a full game will consist of many scenes that can be nested or instantiated multiple times, but for our demo today we’ll only have one. A scene is organised as a tree and requires a root node to start. Press the 3D Scene button in the left hand panel and the left side will change into a navigation window for our current scene:

There is only one entry here and that is our root node called Spatial. A Spatial node simply represents a location in 3D space and helps you organise your scene. With this selected you’ll also see the right hand side of the window changes, here you find the inspector which provides all the settings for the selected node:

In the screenshot above, I’ve expanded the Transform panel which gives us access to the translation (position), rotation and scale of our node. We’ll come back to this in a minute, for now, click on the spatial node on the left hand side, it should allow you to edit the name if the field had focus (alternatively you can right click on the node and select rename). We’ll rename this node to “Main” and save our scene by pressing CTRL-S or selecting save from the Scene menu.

The save dialog in Godot will already name our scene based on its root node and for now we’re happy to save this in the root folder of our project.

Before we can build our demo we need to add our Oculus Rift plugin. Click on AssetLib in the top middle toolbar and search for Oculus in the search bar.

Click on download and it will download the plugin. Once it’s downloaded you will get an install option:

Now this is important. The install dialog will give you the option to download not just the plugin but a load of support files. In a clean project it’s less important but I suggest only leaving everything under the “addons” folder selected or it may overwrite your own files:

Hit install and you’ve successfully added the Oculus module to your project. You can exit the AssetLib by simply pressing 3D in the top toolbar. Our module comes with a few handy support files so we can hit the ground running. With our Main node selected press the link button, this button allows us to add another scene into our own scene. The dialog shows us a list of scenes within our project, we want the oculus_first_person.tscn scene:

Press open to add this and you will see a new entry in our scene tree:

You’ll also see that we’ve got a bunch of things in our 3D viewport, a camera, some controllers, etc:

Our first person scene is a very bare bones starting point without any logic. We now need to write a few lines of code to tell Godot we want to switch over to VR. In our scene tree select the Main node again and press the create script button which is right above:

Godot again will make a suggestion for the scripts name and location and we’re happy with these defaults so we press Create. The main interface will now change over to the script editor. Note in the top toolbar that Script is selected and just as before you can navigate back to the 3D view by pressing 3D. However, we're going to stay on the script tab.

You’ll see some default code and some comments. It’s important to note the default function called _ready. This is automatically called by Godot when our scene is fully loaded and instantiated, and allows us to write some initialisation code. Paste in the following code:

func _ready():
	# Find the interface and initialise
	var interface = ARVRServer.find_interface("Oculus")
	if interface and interface.initialize():
		get_viewport().arvr = true
		
		# make sure vsync is disabled or we'll be limited to 60fps
		OS.vsync_enabled = false
		
		# up our physics to 90fps to get in sync with our rendering
		Engine.target_fps = 90

GDScript is a Python inspired language and follows the same rules for indentation, so make sure the indentation is consistent. The important bits here are the first couple of lines. Everything pertinent to AR and VR is accessed through the ARVRServer so we ask it to find the Oculus driver. If successful we tell our main viewport that it should function as our VR viewport, the rest is some housekeeping you can do through the project settings.

Press the play button in the top right of the editor to run our example Because this is the first time we are running our project, Godot will ask us if we want to select our main scene. Press Select and choose our main.tscn scene. We now have a working VR game, it’s an empty world with a horizon but we can now start filling in our world.

What about the Oculus Go/Quest?

While the above example shows us how to get started with the Oculus Rift, support for Oculus Go and Oculus Quest is on its way, and can already be tested in beta. Getting up and running is nearly identical, you simply need a different driver. To be exact, Godot’s code is portable, so a Godot game written for the Rift will work on the Quest (obvious performance differences notwithstanding).

Godot also has excellent Android integration. You will need the Android SDK installed but once up and running, simply connect your Go or Quest to your PC and press run right from within the Godot IDE. You don’t even need Windows and can run the entire environment on Linux. Please note that support for the Go and Quest will be part of the upcoming Godot 3.2 release.

Where to go from here

Now that we have a real bare bones example there is a long road to travel to turn this into an actual game. We have a few resources to recommend:

Godot also has a very active community with many developers frequenting Facebook, Reddit, IRC and Discord. You can find more information on this on the Godot website.

We hope you’ve enjoyed this introduction into using Godot with the Oculus Rift.

- Bastiaan Olij