Recently I completed an in depth tutorial on Godot 4 and GDScript. During the tutorial I noticed that GDScript has a great potential in being able to implement design patterns suggested by the GO4 (Gang Of Four). It is object oriented and interfaces smoothly with the engine.
There were a few things that I found were more attached to the engine than to the code and these might be areas of improvement for next iterations of Godot however, I think being able to write each and every functionality of the engine in the code is going to be impossible for game engines as they use several different types of assets and inputs that need to be handled at the level of the engine. One example of such an input is the ‘signals’. Signals are feedbacks that are sent by any node in Godot whenever some pre-defined action takes places (collision to other nodes, collision with mouse etc.). Functions can then be written in GDScript which get triggered whenever the signal is received. The signals need to be set using Godot’s interface and then imported into the code. This makes the Godot code deeply coupled with the engine.

I wondered, was it possible to use the Observer pattern in order to handle the broadcast of signals to different classes rather than importing the signals directly into the classes of each node? I didn’t give it much thought but this much was clear to me that there would be a need for being able to create classes which are not associated with in game entities. At this time I am aware that such classes can be created but the entity still needs to be present in the scenes in which its functionality is going to be used. This is not much of a problem as we can create and then instantiate different instances of the same node in Godot and use it across scenes. Including the empty node in all the scenes of the game maybe a bit cumbersome but it can be done and this particular design pattern can be used. However, I haven’t tried it at the time of writing this article.
Anyway, this was my two bits regarding the topic of using design patterns in Godot 4. There is definitely potential for using other design patterns in Godot and if time permits I will attempt to try to apply some of them and share with you the results. Thank you for reading.

Leave a comment