Understanding Key Concepts in Godot Engine for Unity Developers

shadw
4 min readSep 29, 2023

--

For developers who have been working with Unity and are looking to make the switch to Godot Engine, it’s essential to understand the differences and similarities between these two powerful game development tools. Godot offers a wide range of unique features and advantages that can streamline your workflow and enhance your development experience. This article will serve as a foundation for Unity migrants to feel comfortable and oriented in Godot. This is a quick guide to understand Godot Engine for Unity Devs.

Photo by Sean Do on Unsplash

Fundamental Concepts in Godot: Nodes

In Godot, everything revolves around “nodes.” A node is an entity in your scene (very similar to Unity’s “GameObjects”) that can represent anything from 2D and 3D objects to user interface elements, particles, and even scripts. Nodes are organized in a hierarchy, similar to the object hierarchy in Unity. However, Godot has the advantage of allowing nodes to contain scenes (similar to Unity’s “Prefabs”), making it easier to create complex scene structures and reuse elements.

Scenes

In Godot, much like in Unity, all objects are stored in scenes. When you start a new project in Godot, you’ll see a button in the hierarchy panel to add either a “Node2D” or “Node3D,” which is essentially a scene. In Godot, scenes can instantiate other scenes, which is quite similar to the concept of “prefabs” and is essential for reusing objects and building scenes. While Godot doesn’t have an exact equivalent to Unity’s prefabs, it offers a similar solution. You can create scenes with groups of custom nodes and save them for reuse elsewhere. These scenes can be dynamically loaded and added to other scenes, resembling the concept of prefabs.

Explicit Typing in GDScript

The most popular language in Godot is GDScript, which is very similar to Python. In fact, if you know Python, you essentially know GDScript because it mostly changes the names of some keywords. An interesting feature of Godot is the option to use explicit typing in GDScript. Starting from Godot version 3.1, GDScript supports explicitly defining data types, allowing you to declare variable types and function parameters. Although GDScript is a dynamically typed language, meaning it’s flexible like Python or JavaScript, you can use static typing by convention or to improve code documentation. This is particularly helpful for those coming from Unity who prefer the safety of static typing provided by C# and the autocompletion offered by code editors.

Here’s a code snippet demonstrating how to explicitly declare a data type in GDScript:

var name: String = 'Hello, World!'
const vector: Vector2 = Vector2(x, y)

This flexibility is useful for maintaining readable code and helping other developers understand your code.

Accessing Nodes in Godot

Godot offers several ways to access other nodes in your scene. Two of the most common methods are:

- **$NODE_NAME:** Use the ‘$’ symbol followed by the node’s name to access it directly. For example, `$MyCharacter` will allow you to access the node named “MyCharacter.”
- **get_node(“node/path”):** This function lets you access a node using its path in the scene hierarchy. It’s especially useful when working with nodes in separate scenes or when you need to access nested nodes.

Configuring Input Controls (Input Maps)

Configuring input controls in Godot is extremely straightforward and resembles setting up “Input Axes” in Unity. This allows you to define key mappings in one place, keeping your code organized and making it easier to create cross-platform games. To add an input map, go to “Project > Project Settings” and select the “Input Map” tab. From there, you can add new input actions like “left” and “right” and assign the corresponding keys or buttons. This provides a simple way to handle player input in your game.

Key Functions: _ready() and _process(delta)

In Godot, two of the most important functions in your scripts are `_ready()` and `_process(delta)`. `_ready()` is called once at the start of the node and is useful for initializing variables or initial settings. `_process(delta)` is called on every frame and is where you typically place game logic, such as character movement.

extends Sprite2D

func _ready():
var a: String = 'This is equivalent to Unity\'s void Start()'
print(a)

func _process(delta):
var movement: Vector2 = Input.get_vector("left", "right", "up", "down")
position = Vector2(position.x + movement.x * 100 * delta, position.y + movement.y * 100 * delta)
print('This is equivalent to Unity\'s void Update()')

Note About Godot with C#

If you are more comfortable with C# or have previous experience with this language, you can program in Godot using C#. Godot.NET, which utilizes the .NET environment, allows developers to harness the power of C# for game development in Godot. If you are already well-acquainted with C#, you can use Godot.NET for your projects, although there is more documentation available for GDScript, which is an advantage for GDScript.

Conclusion

This article has provided an overview of how to get started with Godot Engine for Unity migrants. It’s important to remember that this guide is just the beginning. Godot is an extremely powerful and versatile platform with much to explore. If this article receives enough support, I will consider creating a more in-depth tutorial that covers step-by-step how to get started with Godot 4 and GDScript. Until then, enjoy exploring and creating in Godot!

--

--

shadw

Hi, I'm Shadw, I'm a software developer, and I want to share my knowledge with anyone who wants to start learning software development. :D