Godot Signalling Methods that Nobody Talks About

preview_player
Показать описание
#godot #gamedev #gamedesign

I hope this solves someone's gamedev problem.

Godot documentation links

Chapters
00:00 Video Start
00:59 Introducing Signals
01:50 Solution Attempt 1: one million custom functions
02:20 Solution Attempt 2: one-func-fits-all
03:15 Solution Attempt 3: the method nobody talks about
05:02 Concluding Thoughts
Рекомендации по теме
Комментарии
Автор

One of my biggest failures in coding is that I rarely look at the documentation so this video has show me what kind of stuff I can miss.

thestormwizard
Автор

In Godot 4, functions are first class objects, which means you can store and access them just like you would do to any other variable. On your last example, that means it should also be possible to do `var function_to_call = map_node.wake_node` instead of using Callable.

An extra tip: If you find that you're defining functions that each are only used by one signal, you can define a lambda function as an argument for said signal. And you can even emit signals with parameters!

# In the script initializing Scout
scout_node.death.connect(
func (scout, time_of_death):
remove_from_nation(scout)
log_death(time_of_death)
)

def log_death(time_of_death):
print("A scout died at %d" % [time_of_death])

# Somewhere else
scout.death.emit(scout, Time.get_ticks_msec())

You can pretty much do anything you can imagine, Godot's signals and functions are that powerful.

georgepitoy
Автор

My type-safe brain aches. But my polymorphic heart is warm.

machine.angel.
Автор

Cool! Some notes:
- you don't have to compare booleans to true (e.g. if x == true: is the same as if x:)
- Callable(object, "method_name") is equivalent to object.method_name I believe
- I think in your final example you _should_ be able to just do

fishnpotatoes
Автор

Recently spent like three hours doing something very similar and im so glad to see someone sharing the solution and the object page signals info. Great video btw :)

curlywuzhere
Автор

the fact that code is secondary when it comes to such a fundamental feature speaks volumes about Godot and its users

sunofabeach
Автор

Honestly I thought the solution was going to be the Grouping feature Godot has. This is pretty neat I'll keep this in mind!

wolfmyths
Автор

I code in C# in Unity and I had a similar issue that I also solved by looking through the documentation. It's honestly the best way to find better ways to do things in coding and is always helpful.

razorsharpplays
Автор

So even though I have no clue about Godot it was still an enjoyable watch and I would love to see some videos on the game development side of things again, especially the actual game design side of things and seeing your plans on how the game is going to play

sylkegaming
Автор

Thanks for making this!
I'm interested in developing strategy games in Godot at some point in the future and I would love to see more videos about your strategy game's programming!

eskoevtyukov
Автор

Something that isn't really mentioned anywhere in the Godot docs is the concept of a signal bus - make a global object and put all your signals in there, then everything can reach out to that channel - either to subscribe, or trigger various signals.

salmonmoose
Автор

Honestly, great find from scouring docs, you're already on the right track imo.
One handy convention I can suggest is to write permanent documentation comments with a space between the # and the comment. eg -> "# This is for documentation purposes"
and for debugging comments to have no space in between them. eg -> "#queue_free()"

It's just a nifty way to separating comments you want to keep and comments born out of doing quick and dirty iterations of stuff.

JJ_Seno
Автор

Very elegant solution, I didn't know you could connect signals to other nodes like that. I'm new as well, and I am definitely more comfortable and more organized limiting my signals and accessing a global script for scene interactions. I'm not sure if that has a negative performance impact or if it might be bad practice for another reason, but so far that has been my preferred solution.

GoDogGame
Автор

Thanks for pointing us to the object page :p
sometimes its good to take a step back and read on the very basics
good luck with your project^^

teamakesgames
Автор

this video has helped me not hate switching to godot

josephleethedeveloper
Автор

5:33 - this method is superior if you're a yanderedev chad who lives off of negative publicity and is still somehow talked about to this very day

TheDoomerBlox
Автор

As someone who is intimidated by reading documentation, this video helped, ty!

JispGames
Автор

Very very very good video talk about how you’re implementing diplomacy and other “civilization” concepts thank

josh_da_guy
Автор

Funnily enough I had to solve a similar problem for a way smaller jam game. There were probably easier, faster ways to solve it, but I'm a sucker for pretty code and since I come from python, where functions are (in theory) first class citizens I figured I could just pass a function to a .connect method. Lo and behold, it did work!

I'm just guessing here, but probably object.connect(self.method_name, "signal_name") would work as well, no need to create a reference to a callable (probably)

Edit: Yeah, way smarter people in the comments said the exact same thing hahahaha. Not deleting the comment tho, enjoy your engagement!

XceptionalBro
Автор

personally I like creating signal handlers that do internal dispatch by binding extra parameters when connecting the signal. Ex:

UODZU-P