Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases now! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Godot 4 Game Development Cookbook
Godot 4 Game Development Cookbook

Godot 4 Game Development Cookbook: Over 50 solid recipes for building high-quality 2D and 3D games with improved performance

eBook
€17.99 €26.99
Paperback
€33.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Product feature icon AI Assistant (beta) to help accelerate your learning
Table of content icon View table of contents Preview book icon Preview Book

Godot 4 Game Development Cookbook

Transitioning to GDScript 2.0

In Godot 4, the GDScript language backend was rewritten, allowing the runtime to be faster and more stable than it was in Godot 3.x. Some additions to the language were also implemented, which we will look at in this chapter: annotations that replace some keywords, such as export; the set and get properties, which replace setget; the await keyword, which replaces yield; and the super keyword, which refers to the parent class object and makes it easier to call the parent class methods.

Typed arrays now allow us to create arrays of a specific type such as all strings, which helps to cut down on errors. We will look at two ways to write a lambda function with a button signal along with other examples using lambda functions. We will also look at two callable static methods and how to use callables with signals.

In this chapter, we will cover the following recipes:

  • Investigating annotations in Godot 4
  • Using properties with getters and setters
  • Using the new await keyword and coroutines
  • Using the super keyword to call a function
  • Working with typed arrays
  • Working with lambda functions
  • Using callables with signals

Technical requirements

For this chapter, you need the standard version of Godot 4.0 or later running on one of the following:

  • Windows 64-bit or 32-bit
  • macOS
  • Linux 64-bit or 32-bit
  • Android
  • Web Editor

You can find the code and the project files for the projects in this chapter on GitHub: https://github.com/PacktPublishing/Godot-4-Game-Development-Cookbook/tree/main/Chapter%202.

Investigating annotations in Godot 4

In this recipe, we will first look at @export and some of the variations associated with that annotation and then show how to use @onready.

Getting ready

For this recipe, open Godot 4 and start a new project called Chapter 2.

How to do it…

To investigate annotations, we will use each in a script by doing the following:

  1. Open a new project in Godot.
  2. In the Scene tab, click 2D Scene.
  3. Click on the paper icon above Node2D and to the right of the filter Search box or in the Inspector tab under Node | Script. Click <empty>, then select New Script, and name the script Annotations.
  4. Click on Script at the top of the editor to look at the new script we added.
  5. @export is the same as export in Godot 3.x, so we will add a score to the node so we can see it in the Inspector tab:
    1  extends Node2D                           
    2     
    3  @export var score = 0
  6. As you saw from the auto-completion, there are new @export options available now. Let’s add @export_range() to line 4:
    4  @export_range(0, 100, .1) var input_range

Note

This gives a range from 0 to 100 in increments of .1 to the input_range variable, which you can change in the Inspector tab.

  1. We can show named enum values in the Inspector tab by adding the following to lines 5 and 6:
                                                          
    5    enum WeatherEnum {Sunny, Rainy, Cloudy = -1}
                                                       
    6    @export var weather: WeatherEnum
  2. On line 7, let’s add a file to show up on the Inspector tab using @export_file:
    7    @export_file("*.txt") var file
  3. Click on Node2D in the Scene tab. Then, click on + under Scene in the Scene tab to bring up the Create New Node window.
  4. Then, type camer2d in the Search box. Select and add Camera2D to Node2D.
  5. The onready keyword is now @onready. We will add a Camera2D node and use @onready with the camera on line 7:
    8    @onready var camera = $Camera2d
  6. Click on Node2D at the top of the tree in the Scene tab to see everything we used with @export in the Inspector tab.
Figure 2.1 – Annotations.gd

Figure 2.1 – Annotations.gd

How it works…

We added a score variable so we can could see it in the Inspector tab using @export instead of the export keyword.

We added @export_range(0, 100, .1) var input_range to show a range of 0 to 100 that snapped the value in .10 increments. You could also just use @export_range (0, 100) var input_range or @export_range (0, 100) var input_range: float.

We created an enum and then we used @export var weather: WeatherEnum to put the enum into the weather variable so we could see it in the Inspector tab. You could also do @export_enum(Sunny, Rainy, Cloudy) var weather.

We used the @export_file("*.txt") var file to show how a file is seen in the Inspector tab.

We added a Camera2D node to Node2D so we could use @onready with it. First, we just used @onready var camera = $Camera2d to add the Camera2D node to the camera variable.

Using properties with getters and setters

In Godot 4, the setget keyword is gone and has been replaced by using properties, so you don’t have to use dedicated functions. We will go through some examples of how to use getters and setters.

Getting ready

For this recipe, create a new scene by clicking + to the right of the current Scene tab and add Node2D. Click on the word Scene in the top menu next to Project, then select Save Scene As, and name it Properties.

How to do it…

There are two ways we can use getters and setters. The first is like Godot 3.x, where we assign get and set to functions. The second way is to define get and set after we declare the variable. First, let’s create a button:

  1. In the new scene named Properties that you created, add a Button node and make it big enough to see.
Figure 2.2 – Creating a Button node

Figure 2.2 – Creating a Button node

  1. Add a script named Properties.gd to the Button node and delete everything except for line 1.
  2. At the top center of the editor, left-click on 2D in the Workspace section. Add a signal to the Button node by going to the Node tab to the right of the Inspector tab located under BaseButton and selecting pressed():
    1  extends Button       
    2                                                 
    3     
  3. The setget keyword used in Godot 3.x is now gone. We will assign get and set to functions as was done in Godot 3.x:
    5  var value: int = 10: set = set_value, get = get_value                         
    6                                                   
    7  func set_value(new_value: int) -> void:            
    8     value = new_value                          
    9     print('setter', str(value))               
    10             
    11 func get_value() -> int:                         
    12    print('getter', str(value))               
    13    return value                              
    14            
    15 func _on_pressed():                              
    16    value -= 1                              
  4. Now click the Run the current scene button or hit the F6 key. Look at the Output section in the bottom panel.
  5. Highlight lines 5–13 and hit Ctrl + K to comment out these lines.
  6. Now we will try using a variable declaration and no functions. Let’s start on line 15. Lines 23 and 24 should still be there from step 4. They were lines 15 and 16:
    15 var value: int = 10:            
    16     set(new_value):             
    17        value = new_value                         
    18        print('setter', str(value))          
    19     get:                                        
    20        print('getter', str(value))          
    21        return value                              
    22             
    23 func _on_pressed():                             
    24     value -= 1                         
  7. Now click the Run the current scene button or hit the F6 key.

How it works…

We added a button and connected the pressed() signal so we could see that the getters and setters were working.

In lines 7–9, we created the set_value setter function with an integer parameter called new_value. This function does not return a value so we used -> void:. We then made value equal to new_value, and finally, we printed setter with value.

In lines 11–13, we created the get_value getter function, which returns an integer, so we used -> int:. We printed getter with value and then we returned value. In line 16, we added value = value – 1 to the _on_pressed() function that was created when we hooked up the signal in step 3.

We entered the code to call the get and set functions as was done using the getset keyword in Godot 3.x. In line 5, we created a variable called value, which is an int value equal to 10. We then assigned set to the set_value function and get to the get_value function.

Figure 2.3 – The GDScript and console output results

Figure 2.3 – The GDScript and console output results

When the button was clicked, the value variable in the setter was decreased by one and then printed on the console, as well as the value getter variable before and after the button was pushed, to show that the getter and setter were working.

We commented out lines 5–13 so we could use the get and set properties with the variable declaration.

On line 15, we created an integer variable called value and assigned it to equal 10. Then, on line 16, we used the set property with new_value as the parameter. On lines 17–18, we made value equal to new_value and printed setter with value. On line 19, we saw the get property. On lines 20–21, inside of the get property, we printed getter with value.

Figure 2.4 – The GDScript and console output results

Figure 2.4 – The GDScript and console output results

We select Run the current scene and notice that we get the same output on the console as we did when we used functions. The value variable in the setter is decreased by one and then printed on the console, as well as the value getter variable before and after the button was pushed.

Using the new await keyword and coroutines

The yield keyword has been removed and replaced by the await keyword. You can use await with coroutines or signals. It pauses the function it is in and waits for a signal to be emitted, or if a called coroutine is finished, it then resumes the function where it was originally called.

Getting ready

For this recipe, create a new scene by clicking + to the right of the current Scene tab and adding Node2D. Select Save Scene As and name it Await.

How to do it…

We will go through a very simple example of how await works with a coroutine using a button as a character dialogue box. When the button is clicked, it skips to the next character dialogue box:

  1. In the new scene named Await that you have created, add a Button node and make it big enough to see the text that we are going to place in it with code.
  2. Add a script named Await to Node2D and delete all of the default lines except line 1.
  3. Let’s use @onready and create a variable called button to reference our Button node:
    1  extends Node2D                                   
    2                                                  
    3  @onready var button = $Button
  4. On line 5, we will create a new function called game_dialogue() and call it in the _ready() function:
    4                                          
    5  func _ready():                               
    6     game_dialogue()                         
    7      
    8  func game_dialogue():                          
    9     button.text = "Dialogue text."               
    10    print("In the game_dialogue function.")     
    11    var next_dialogue = await skip_dialogue()    
    12    if next_dialogue:                    
    13       print("At the end of game_dialogue function.")
  5. On line 15, we created a new function called skip_dialogue():
    15 func skip_dialogue():              
    16    print("Now in the skip_dialogue() function.") 
    17    await button.button_up                    
    18    button.text = "New dialogue text."          
    19    print("At the end of skip_dialogue function." 
    20    return true
  6. Now click the Run the current scene button or hit the F6 key.
Figure 2.5 – GDScript for steps 3 to 5 (the code for Await.gd)

Figure 2.5 – GDScript for steps 3 to 5 (the code for Await.gd)

How it works…

We added a Button node and made it big enough for us to read the text on the button that we will code in later. Then we added a script called Await to Node2D and deleted all of the default lines except line 1.

We used @onready with the button variable so we could load the reference when the _ready() function was called.

We created a function called game_dialogue(). In line 9, we added text to the button. In line 10, we printed that we were in this function so we could see it in the console to see how the await keyword works. In line 11, we declared a variable called next_dialogue equal to the skip_dialogue() function written in step 5.

This is where the program will pause and go to the coroutine of the skip_dialogue() function. In lines 12–13, we have an if statement that checks that next_dialogue is true, and if so, then prints that we are back in the game_dialogue() function. For it to be true, the skip_dialogue() function has to run and return true.

We created the function called skip_dialogue(). In line 16, we printed to the console that we were now in this function. In line 17, we waited for the user to click the button. In line 18, we changed the text on the button. In line 19, we printed to the console that we were at the end of the skip_dialogue() function. In line 20, we return true so that when we go back to the game_dialogue() function, we can print the last print statement.

We selected Run the current scene.

You see In the game_dialogue function. and Now in the skip_dialogue() function. on the console before you click the button. The default text on the button is Dialogue text.. After you click the button, you see At the end of skip_dialogue function. and At the end of game_dialogue function. on the console and the text on the button is New dialogue text..

Using the super keyword to call a function

In Godot 3.x, we used to call a function of the parent class from a subclass by using the .function of the parent class. Now we use the super keyword. In the example, we will use in this recipe, we have SniperEnemyClass, which is inherited from DefaultEnemyClass. If we wanted to call the rifle function in DefaultEnemyClass from SniperEnemyClass, we would use the super keyword, but in Godot 3.x, we use .rifle().

Getting ready

For this recipe, create a new scene by clicking + to the right of the current Scene tab and clicking Node2D. Select Save Scene As and name it Super.

How to do it…

We will create two classes called SniperEnemyClass, which is inherited from DefaultEnemyClass. The DefaultEnemyClass class has two functions called rifle and orders. We will use the super keyword from SniperEnemyClass to call the two functions:

  1. Add a script named Super to Node2D and delete all of the default lines except line 1.
  2. Let’s start on line 11 and create DefaultEnemyClass:
    11 class DefaultEnemyClass extends Node2D:          
    12     func rifie():                   
    13        print("Basic rifle")                        
    14     func orders():                              
    15        print("Guard the front gate.")
  3. Now let’s create SniperEnemyClass starting on line 17:
    17 class SniperEnemyClass extends DefaultEnemyClass:
    18     func rifle():                              
    19        print("Sniper rifle")                   
    20        super.orders()                          
    21        super()
  4. We need to add a couple of variables to the _ready() function so we can see the output of the print statement on the console. Let’s start on line 3:
    3  func _ready():                           
    4      var enemy = DefaultEnemyClass.new()          
    5      var sniper = SniperEnemyClass.new()          
    6  
    7      enemy.rifle()                                
    8      enemy.orders()                              
    9      sniper.rifle()
  5. Now click the Run the current scene button or hit the F6 key.
Figure 2.6 – super keyword code (GDScript for steps 2–4)

Figure 2.6 – super keyword code (GDScript for steps 2–4)

How it works…

We added a script to Node2D and named it Super. Then we deleted all of the lines in the script except line 1.

We made a class called DefaultEnemyClass, which extends Node2D so, later, we can see the output on the console. In lines 12–13, we made a function called rifle to print out a rifle. In lines 14–15, we made a function called orders to print out the orders.

We made a class called SniperEnemyClass, which extends DefaultEnemyClass. In lines 18–19, we created a rifle function, which prints out a sniper rifle. In line 20, we called the orders function in the DefaultEnemyClass class using the super keyword. In line 21, we called the rifle function in DefaultEnemyClass from SniperEnemyClass using the super() keyword. As long as you are in a function that is in both parent and child classes, you can use super(). If you want to call a different function in DefaultEnemyClass, then you have to use super.function.

In lines 4–5, we created enemy and sniper instances for the two classes. In line 7, we called the rifle() function in DefaultEnemyClass to see which rifle was set as the default. In line 8, we called the orders() function in DefaultEnemyClass to see the enemy orders. In line 9, we called the rifle() function in SniperEnemyClass.

We ran the current scene. We saw Basic rifle, Guard the front gate., Sniper rifle, Guard the front gate., and Basic rife on the console.

We get the following console output when we run the current scene:

Figure 2.7 – super keyword console output

Figure 2.7 – super keyword console output

Working with typed arrays

In Godot 4, we can use typed arrays so if you are only going to use an array of strings, you can set the element type to String and Godot will throw an error if you try to put anything other than a string in that array. Types are validated at runtime and not when compiling, which causes slightly faster performance.

Getting ready

For this recipe, create a new scene by clicking + to the right of the current Scene tab and adding Node2D. Select Save Scene As and name it TypedArray.

How to do it…

In this recipe, we are going to set up three arrays. The first is not a typed array, the second is a typed array, and the third infers the type of the array:

  1. Add a script named TypedArray to Node2D and delete all the default lines except line 1 and the _ready() function.
  2. On line 3, let’s create a regular array:
    1  extends Node2D  
    2                                                  
    3  var regular_array = [4, "hello",434]         
  3. On line 4, we will create a typed array of int. Try adding a string to this array:
    4  var typed_array: Array[int] = [16, 32, 64]        
  4. On line 5, we will create an inferred array of string. Try adding an integer to this array:
    5  var inferred_array := ["hi", "hello"]     
  5. On lines 7–10, in the _ready() function, we print out all the arrays to the console:
                                                      
    7  func ready():                                   
    8      print(regular_array)                         
    9      print(typed_array)                             
    10     print(inferred_array)                    
  6. Now click the Run the current scene button or hit the F6 key.
Figure 2.8 – GDScript for steps 2 to 5

Figure 2.8 – GDScript for steps 2 to 5

How it works…

We added a script to Node2D and named it TypedArray. Then we deleted all of the lines in the script except line 1 and the _ready() function. We created a regular array with two integers and one string value. We can put anything in this array.

We created a typed array of int and tried to enter a string in the array to see the resulting error. In step 4, we created an inferred array of String and tried to enter an integer into the array to see the resulting error.

We printed out all of the arrays to the console. We ran the current scene. We saw [4, "hello", 434], [16, 32, 64], and ["hi", "hello"] printed on the console.

Working with lambda functions

In this recipe, we are going to go through some examples of how to use lambdas in Godot 4. First, we create a lambda that takes a greeting parameter, then we will call the lambda and pass in "hello" to the parameter. In the next example, we declare a variable called health outside of the player_health lambda and call the variable inside of the lambda. We will learn two ways to write a lambda function with a button signal. Finally, we use a lambda function, moving the button across the screen with a tween.

Getting ready

For this recipe, create a new scene by clicking + to the right of the current Scene tab and adding Node2D. Select Save Scene As and name it Lambda.

How to do it…

Let’s start by creating a Button node and referencing it to the button variable:

  1. Add a script named Lambda to Node2D and delete all of the default lines except line 1 and the _ready() function.
  2. In the new scene named Lambda that you created, add a Button node and make it big enough to see.
  3. Let’s use @onready and create a variable called button to reference our Button node:
    1  extends Node2D                                   
    2                                                  
    3  @onready var button = $Button
  4. On line 5, in the _ready() function, we create a lambda that will pass in "hello" to the lambda parameter greeting:
    5  func _ready():            
    6      var lambda = func(greeting):                   
    7          print(greeting)                         
    8      lambda.call("hello")                        
  5. On line 10, we declare a variable called health:
    10     var health = 100 
  6. On line 11, we create a lambda function called player_health:
    11     var player_health = func(): print("Current health ", health)
  7. On line 12, we call the player_health lambda function:
    12     player_health.call()                    
  8. On line 14, we create a lambda function to run when the button is pressed:
    14     button.pressed.connect(func(): print("button was pressed"))
  9. On lines 16–18, we create a lambda to run when the button is released:
    16     var button_released = func():               
    17         print("Button released")                  
    18     button.button_up.connect(button_released)
  10. On lines 20–21, we create a tween to move the button across the screen:
    20     var tween = create_tween()        
    21     tween.tween_method(func(pos): button.position.x = pos, 0, 500, 1)
  11. Now click the Run the current scene button or hit the F6 key.
Figure 2.9 – Lambda code (GDScript for steps 3–10)

Figure 2.9 – Lambda code (GDScript for steps 3–10)

How it works…

We added a script called Lambda to Node2D and deleted everything in the script except line 1 and the _ready() function. Then, we created a Button node in the Scene tab. In the Lambda script, we used @onready to declare a variable called button to the Button node.

We created a variable called lambda equal to the lambda function with the greeting parameter, which prints the greeting. Since lambdas are a type of callable, we call the lambda variable with the "hello" string to be used as the greeting.

We declared a variable called health and gave it a value of 100 in line 10. You can use variables from the outer class or outer function inside the lambda. In line 11, we created a lambda called player_health, which prints out Current health and the value of the health variable. In line 12, we call the player_health lambda to print out ("Current health ", health) to the console.

We pass the lambda as a function argument. When the pressed() button signal is emitted, Button was pressed will be printed to the console.

We essentially do the same thing we did last in the step except we use more than one line. When the button_up() signal is emitted, Button released is printed to the console.

On line 20, we create a tween. On line 21, we use a lambda in tween_method() to move the Button node from position (0) to position (500) with a duration of (1). If we wanted the button to go slower, we would increase the duration number.

We run the current scene. It shows the button move across the screen and on the console, you will see "hello" and "Current health 100". After you click the button, you will see Button was pressed and Button released.

Figure 2.10 – Button and console output

Figure 2.10 – Button and console output

Using callables with signals

In this recipe, we will see how callables can be used with signals. We will also look at the call and bind callable methods. Callables can be held in variables and passed into functions. As such, you can use them in arrays and in dictionaries as the key or the value.

Getting ready

For this recipe, create a new scene by clicking + to the right of the current Scene tab and adding Node2D. Select Save Scene As and name it Callables.

How to do it…

Let’s start by creating a Button node and referencing it to the button variable:

  1. Add a script named Callables to Node2D and delete all of the default lines except line 1 and the _ready() function.
  2. In the new scene named Callables that you created, add a Button node and make it big enough to see.
  3. Let’s use @onready and create a variable called button to reference our Button node:
    1  extends Node2D                                   
    2       
    3  @onready var button = $Button
  4. On line 8, we create a function called signal_callable():
    8  func signal_callable():             
    9      print("This method was called by the button pressed signal.")
  5. On line 5, in the _ready() function, we connect a callable signal to the signal_callable() function:
    5  func _ready():                                    
    6      button.pressed.connect(signal_callable)
  6. Now click the Run the current scene button or hit the F6 key.
  7. Let’s use the .bind method when we connect the signal. On line 6, add .bind after signal_callable:
    6      button.pressed.connect(signal_callable.bind("binding_")) 
  8. We need to add a parameter to the signal_callable function:
    8  func signal_callable(param):         
    9      print(param, "This method was called by the button pressed signal.")
  9. Now click the Run the current scene button or hit the F6 key.
  10. Let’s add a new function on line 11 called player_text:
    10 func player_text(param: String):                
    11     print(param)              
  11. Go to line 7, hit the Tab key, and add more code to the ready function.
  12. Let’s create a variable called pt equal to player_text:
    7      var pt = player_text      
    8      pt.call("Hello, NPC!")          
  13. Now click the Run the current scene button or hit the F6 key.

How it works…

We added a script called Callables to Node2D and deleted everything in the script except line 1 and the _ready() function. Then we created a Button node in the Scene tab. In the Callables script, we used @onready to declare a variable called button to the Button node.

We created a function that we want to run when the button pressed signal is true. Notice that we don’t have to connect the signal in the editor. We can use any method that we want.

In the _ready() function, we used the button reference to connect the signal_callable function when the signal pressed is true, which happens when the button is pressed.

We ran the current scene. In the console, we saw This method was called by the button pressed signal. after we clicked the button.

Figure 2.11 – Using callables with signals (code for steps 4–6)

Figure 2.11 – Using callables with signals (code for steps 4–6)

We used the callable bind method. In line 6, we added .bind like this:

button.pressed.connect(signal_callable.bind("binding_")).

We needed to add a parameter to the function and inside of the print statement to see what we added with bind.

We ran the current scene. In the console, we saw binding_This method was called by the button pressed signal. printed after we clicked the button.

Figure 2.12 – Using callable with the bind method (code for steps 7–9)

Figure 2.12 – Using callable with the bind method (code for steps 7–9)

We added a function called player_text, which takes a parameter called param that only accepts strings. It prints out the parameter that will be passed in when we use .call.

We created a variable for the player_text() function When you enter var pt = player_text, autocomplete wants to add the () at the end – make sure you delete it. We converted the function into a variable, so now we can use the function in arrays, dictionaries, or in any other way you can use a variable.

We ran it to see Hello, NPC! printed in the console.

Figure 2.13 – Using .call() with a variable of the function (code for steps 10–13)

Figure 2.13 – Using .call() with a variable of the function (code for steps 10–13)

Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • Take advantage of the new Vulkan renderer and 3D physics in Godot 4 to create high-quality games
  • Streamline your game development workflow with Godot’s new TileMap, TileSet, and Animation Editor features
  • Discover what’s changed in GDScript 2.0 and Shader additions to enhance your game development skills

Description

Want to transition from Godot 3 to 4? Look no further than the Godot 4 Game Development Cookbook. This comprehensive guide covers everything you need to become proficient with the latest GUI, GDscript 2.0, Vulkan 2D/3D rendering, shaders, audio, physics, TileSet/TileMap, importing, sound/music, animation, and multiplayer workflows. With its detailed recipes, the book leaves no stone unturned. The Godot 4 Cookbook begins by exploring the updated graphical user interface and helps you familiarize yourself with the new features of GDscript 2.0. Next, it delves into the efficient rendering of 2D and 3D graphics using the Vulkan renderer. As it guides you in navigating the new Godot 4 platform, the book offers an in-depth understanding of shaders, including the latest enhancements to the shader language. Moreover, it covers a range of other topics, including importing from Blender, working with audio, and demystifying the new Vulkan Renderer and the physics additions for 2D and 3D. The book also shows you how the new changes to TileSet and TileMap make 2D game development easy. Advanced topics such as importing in Godot 4, adding sound and music to games, making changes in the Animation editor, and including workflows for multiplayer in Godot 4 are covered in detail. By the end of this game development book, you’ll have gained a better understanding of Godot 4 and will be equipped with various powerful techniques to enhance your Godot game development efficiency.

Who is this book for?

The Godot 4 Game Development Cookbook is for seasoned game developers who want to acquire skills in creating games using a contemporary game engine. It is an invaluable resource for indie game developers and Godot developers who are familiar with Godot 3 and have some level of expertise in maneuvering the interface.

What you will learn

  • Speed up 2D game development with new TileSet and TileMap updates
  • Improve 2D and 3D rendering with the Vulkan Renderer
  • Master the new animation editor in Godot 4 for advanced game development
  • Enhance visuals and performance with visual shaders and the updated shader language
  • Import Blender blend files into Godot to optimize your workflow
  • Explore new physics system additions for improved realism and behavior of game objects
  • Experience innovative features by building multiplayer games in Godot 4

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Jun 09, 2023
Length: 258 pages
Edition : 1st
Language : English
ISBN-13 : 9781838827250
Languages :
Tools :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Product feature icon AI Assistant (beta) to help accelerate your learning

Product Details

Publication date : Jun 09, 2023
Length: 258 pages
Edition : 1st
Language : English
ISBN-13 : 9781838827250
Languages :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
€18.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
€189.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts
€264.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 105.97
Godot 4 Game Development Projects
€33.99
The Essential Guide to Creating Multiplayer Games with Godot 4.0
€37.99
Godot 4 Game Development Cookbook
€33.99
Total 105.97 Stars icon

Table of Contents

12 Chapters
Chapter 1: Exploring the Godot 4 Editor Chevron down icon Chevron up icon
Chapter 2: Transitioning to GDScript 2.0 Chevron down icon Chevron up icon
Chapter 3: 2D and 3D Rendering with Vulkan Chevron down icon Chevron up icon
Chapter 4: Practicing Physics and Handling Navigation in Godot 4 Chevron down icon Chevron up icon
Chapter 5: Playing with Shaders in Godot 4 Chevron down icon Chevron up icon
Chapter 6: Importing 3D Assets in Godot 4 Chevron down icon Chevron up icon
Chapter 7: Adding Sound and Music to Your Game Chevron down icon Chevron up icon
Chapter 8: Making 2D Games Easier with TileSet and TileMap Chevron down icon Chevron up icon
Chapter 9: Achieving Better Animations Using the New Animation Editor Chevron down icon Chevron up icon
Chapter 10: Exploring New Multiplayer Features in Godot 4 Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon
Other Books You May Enjoy Chevron down icon Chevron up icon

Customer reviews

Most Recent
Rating distribution
Full star icon Full star icon Full star icon Full star icon Half star icon 4.1
(17 Ratings)
5 star 41.2%
4 star 35.3%
3 star 11.8%
2 star 11.8%
1 star 0%
Filter icon Filter
Most Recent

Filter reviews by




Kostas Jul 14, 2024
Full star icon Full star icon Full star icon Empty star icon Empty star icon 3
This book is hard to follow especially if you're not in front of a computer with godot running. The way the instructions are written is too verbose. It would be much simpler and even readable even if not in front of the godot editor if the instructions were presented as say a tree regarding which godot UI buttons you should click.Also the table of contents are quite copy paste of "getting ready" , "how to do it" , "how it works" without mentioning what exactly will you learn by following them.
Amazon Verified review Amazon
Eddie Dec 08, 2023
Full star icon Full star icon Empty star icon Empty star icon Empty star icon 2
All of the information in this book can be found online. It's also not very good since Godot 4 is very new (at the time of this review) so the author tried to shoehorn in things that they themselves don't even understand well, like the new multiplayer objects. Save yourself the money and just look at the code/projects on their repository. This book itself is absolutely unnecessary.
Amazon Verified review Amazon
David Mackie Sep 24, 2023
Full star icon Full star icon Empty star icon Empty star icon Empty star icon 2
This book is 230 pages of screenshots and filler.For example, every recipe REPEATS the requirements to install Godot 4. WTF? Why are those requirements repeated as late as page 215 of a 230 page book?What I'm most disappointed about with this book is that the World *needs* a good Godot 4 Cookbook. This is an impostor that occupies that niche but doesn't satisfy -- just diminishes it for more serious efforts.I have dozens of Software Dev Cookbooks - most have over 1000 pages.The screenshots are in colour so +1, but most of them are just shots of properties windows, not illustrating concepts, procedures, or practices.
Amazon Verified review Amazon
Amazon Customer Jul 16, 2023
Full star icon Full star icon Full star icon Empty star icon Empty star icon 3
The book was very limited and not a good introduction to Godot 4.Very thin book and not worth the price of £29.The recipes were very random and didn't go into much detail on the topics.The knowledge I've gained over the last few months with Godot 4 following online tutorials could make for a book 4 times the thickness and then some.I've purchased other similar books for Unity and Unreal which have a whealth of info with things you might actually want to know.There was also a lack of screenshots, which for beginner's to Godot would find a bit of a slog trying locate buttons, menus etc.Mostly each recipe consists of following a large list of steps a screenshot or two and then a brief rundown of what you've just done.Very dull and not focused on how a game dev might work with the mindset of developing an entertaining game.A missed opportunity and it makes me a little sad that an engine with a lot of potential is being taught by those that are not gamers or understand real game mechanics and flow.Until something better is published, stick to online tutorials.
Amazon Verified review Amazon
Trevor Harron Jul 14, 2023
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
If you are looking for a book to help you experience the new key features of Godot 4, this book is for you! The author put a lot of effort into breaking down and showcasing the the new functionality of Godot 4 and it pays off.This book is not for people completely new to Godot but is good for folks that want to improve on the basics they have built up.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.