🤖 Trying Godot 4
I have been hearing a lot of good things about Godot for game development, and thought it would be a good time to try it out and write a post on trying Godot 4. Godot is a full-featured game engine like Unity or Unreal. The biggest difference it that it is free and open-source software (FOSS). You need to look no further than the 3D modelling and editing Blender toolset to see how community driven development creates software on a par with proprietary alternatives.
FOSS advancements can track user needs. Studios adopting Godot, instead of building and maintaining their own in-house engine, leverage on community contributions. Further, they provide Godot improvements, useful for their own games, and then share those improvements back to the community.
There are already successful Godot games available on Steam, such as Brotato, Ex-Zodiac (in early access at time of writing), and Halls of Torment.
In the rest of this post, we take a closer look at why you might choose Godot and also see some video and website resources for starting out with Godot.
🤔 Why Godot?
In short:
- Godot has batteries included; it is a full-featured and intuitive game engine helping you churn out your game quicker,
- it is FOSS, so you do not have to pay to use Godot or pay royalties on games you create with it; and
- it is popular - it keeps improving with community contributions, and you can find quality learning resources.
My first impression was that Godot is lightweight. I loved that you could download, install and start coding far quicker than other engines which have gigantic downloads. Despite that, Godot is still powerful. Not only is Godot powerful, but the user interface, is snappy and intuitive.
Finally, here, I would say the flexibility in code language for the game logic is another strength. The easiest way to code, is to use GDScript, which looks like Python. However, if you need performance, you can use GDExtension which lets you code in C, C++ or, thanks to a donation from Microsoft, C#. Language support does not end there though; community projects also add support for Rust, Swift, Zig and Go as well as other languages.
🏅 Official Godot Getting Started Guide
The official tutorial is well-written and provides a direct route for getting you up-to-speed on the Godot engine. If you want to get a feel for Godot before diving in though, first try the Brackeys How to make a Video Game video tutorial (mentioned further down). You can then loop back and learn more fundamentals once you have a better idea of whether it is something that will suit you.
- The official guide starts with an Introduction, giving you an overview of Godot’s capabilities.
- You then jump onto some Godot concepts, before moving onto the Instancing Tutorial, which provides a first look at Godot Code.
- The guide wraps up with creating a 2D and then, 3D Godot game, before you are let loose to build that game idea you have had running through your mind for months!
🏞️ Godot Design: Scenes, Nodes and Signals
Godot promotes an Object-oriented Programming (OOP) approach to games architecture, which contrasts to the Entity Component System (ECS) used by Bevy, for example.
Godot Scenes are game elements, such as collectable coins, a moving platform or even a player.
Scenes might be composed of multiple Godot built-in Nodes. Nodes are OOP objects providing some logic or behaviour. For example, the collectable coin scenes have:
- a 2D collider node (used to detect that the player character has walked into the coin),
- an
AudioStreamPlayer
node to play a sound effect when the coin is picked up; and - one each of an
AnimationSprite
andAnimationPlayer
node.
Scenes are combined into a Scene Trees: the game scene includes collectable coin and player scenes in its scene tree.
Signals: Communicating between Remote Scenes
Signals provide a convenient interface communicating between scenes at different levels of the game. There are built-in signals, triggered when a button is pressed, but you can also create your own. For example, you could create a lava scene with an on_body_entered
signal, emitted when the player falls into the lava. Now, the score readout, life count and other independent components just need to listen for that signal to update themselves. No need to poll on every game tick to check if they need to update.
🧩 Composition is Still Possible
ECS designs favour composition over inheritance, making certain common relationships easier to code. Godot allows for composition, adding custom components to a class. This is a little beyond the scope of this post, though the How You Can Easily Make Your Code Simpler in Godot 4 video provides an excellent explanation with great examples.
🖥️ Coding your Godot Game
I mentioned above, that GDScript is a good choice if you want to get going quickly and other languages, available via GDExtension can provide more performant alternatives where that is most important.
Trying Godot 4: GDScript
GDScript looks a lot like Python. In fact, earlier versions of Godot supported coding in Python, though Python was replaced by GDScript to address Python for game development shortcomings. GDScript is quite intuitive and supports static types. Here is an example, in case you are curious to see some code:
extends Node2D
const SPEED := 60
var direction: int = 1
@onready var ray_cast_right = $RayCastRight
@onready var ray_cast_left = $RayCastLeft
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
if ray_cast_right.is_colliding():
direction = -1
if ray_cast_left.is_colliding():
direction = 1
position.x += direction * SPEED * delta
This code moves a monster back and forth between two walls. Here:
-
_process
is the in-built function run on every frame for our scene. Engine function names begin with an underscore. -
const SPEED := 60
creates the constant property, inferring its type to be integer from the value provided. The typing is optional, and the statement could be writtenconst SPEED = 60
for dynamic typing. -
var direction: int = 1
uses an explicit static type. Godot would throw up an error if we later tried to assign a string, for example, to direction.
Learning GDScript
The Brackeys have a broad-strokes overview of GDScript, in a one-hour video. This is a different video to the Godot introduction from the same creator, mentioned further down. Some, older, content on YouTube covers GDScript for Godot 3. Godot 4 was released over a year ago now, and is stable, so you will probably want to focus on Godot 4 for any new games you create.
Trying Godot 4: GDExtension for Rust, Swift, C++, C#, Zig and more…
When you need performance, GDExtension will probably be your best bet. GDExtension lets you compile a shared library using third-party C bindings. Shared libraries are compiled independently of the game, but still can be called from your game code. Because GDExtension creates shared libraries, you can use the same library in different games, or distribute it, without having to compile with the engine’s source code.
You target a particular Godot engine version when you write GDExtension. If you target 4.2 (latest version at time of writing), you get to use the latest Godot features and your code will be compatible with future Godot Engine versions. That said, your Godot 4.2 targeted GDExtension library might not work with Godot Engine 4.1 and earlier versions.
Watch the 6 Programming Languages in 1 Godot Game! Trying out GDExtension! video to get a better fell for how this works.
GDExtension Tutorials
For tutorials see:
- Godot’s official Godot C++ GDExtension tutorial;
- the godot-rust book, which takes you through setting up your first Rust GDExtension game; or
- the SwiftGodot tutorial.
📼 Free Video Tutorials
Here are some free tutorials you can access on YouTube to get going with Godot. The first two, shorter ones assume a little previous programming knowledge.
- The Brackeys (known for Unity content) have recently started putting out Godot 4 content. Create a 2D platform game in the How to make a Video Game - Godot Beginner Tutorial. Around 80 minutes.
- Create a rogue-like shoot-em-up in the same vein as Brotato and Halls of Torrent in the Your First 2D GAME From Zero with GODOT 4! video from GDQuest. Just over two hours.
- Build a 3D Godot 4 Platformer in the 3D for coding beginners series. Creator has a background in eduction and targets all levels including coding novices. 11 videos, 5 hours in total.
If plan to work offline, remember to check the video descriptions for game asset downloads needed to complete the tutorials.
🏁 Where Next?
If you are looking for a roadmap for getting going on Godot my two cents it to try these steps in this order:
- the Brackeys How to make a Video Game - Godot Beginner Tutorial video, for an overview of Godot building your own game in under two hours without having to get too concerned with the details;
- the official Godot tutorial to learn some fundamentals in more detail; and
- the Brackeys GDScript tutorial.
From there, you can explore a path taking in Godot aspects best suited for the game you want to work on, including the other resources listed above.
🙌🏽 Trying Godot 4: Wrapping Up
In this trying Godot 4 post, we took a look through some resources for getting started with Godot. In particular, I talked about:
- why you might choose Godot;
- Godot options for coding language, including GDScript, C++, C#, Rust and Swift; and
- some Godot 4 tutorials.
I hope you found this useful. I would love to hear from you, if you are also new to Godot video game development. Were there other resources you found useful? Also, let me know what kind of game you are working on!
🙏🏽 Trying Godot 4: Feedback
If you have found this post useful, see links below for further related content on this site. Let me know if there are any ways I can improve on it. I hope you will use the code or starter in your own projects. Be sure to share your work on X, giving me a mention, so I can see what you did. Finally, be sure to let me know ideas for other short videos you would like to see. Read on to find ways to get in touch, further below. If you have found this post useful, even though you can only afford even a tiny contribution, please consider supporting me through Buy me a Coffee.
Finally, feel free to share the post on your social media accounts for all your followers who will find it useful. As well as leaving a comment below, you can get in touch via @askRodney on X (previously Twitter) and also, join the #rodney Element Matrix room. Also, see further ways to get in touch with Rodney Lab. I post regularly on Game Dev as well as Rust and C++ (among other topics). Also, subscribe to the newsletter to keep up-to-date with our latest projects.
Top comments (0)