Godot 4 Tutorial - The Message Bus Pattern

preview_player
Показать описание
Learn how to implement a message bus for more efficient signaling in Godot 4.
Рекомендации по теме
Комментарии
Автор

Fantastic tutorial. It conveys the bare minimum of information for understanding, then leaves. Nothing about syntax, or any of the detailed stuff I can find in the documentation, just the raw structure, basic workflow, and general design pointers. Thank you so much for making this!

jupitersky
Автор

My man really rocking Windows 7 in the year of our lord 2023.

donoteatmikezila
Автор

You should always add „if old_value == new_value: return“ to the beginning of all setters. Not only will it reduce unnecessary load, it will also automatically break circles between nodes that sync each other (like UI elements that reflect properties and that can also change the properties). This is also how the property changed signals in QML work.

oliverkuss
Автор

This is truly a gem.

I think this problem with signals should be addressed by the Godot devs somewhere in the future.

jorgegomes
Автор

Thank you for this video, I went through the documentation and didn't quite grasp the explanation but this helped me figure out what I was misunderstanding right away. I'm writing a visible checkpoint system where the on-body contact is supposed to update all other nodes of the same type to not be the primary one. A message bus is the perfect solution for getting them to all acknowledge their status without talking to each other.

sunnysatellites
Автор

I LOVE this pattern, use it all the time, and will die on this hill. :) I previously worked with someone who swore up and down that it was bad programming and a terrible pattern. We don't work together anymore.

WarrenMarshallBiz
Автор

It's also useful for having a centralized place where you can control the flow of data for things like settings in your games menu.

AkaiKnight
Автор

Thanks for the video! I would use constants instead of magic strings though, makes your life a lot easier.

blaaahization
Автор

I was considering implementing *exactly* this, and wanted to check if there is a trick somewhere I missed. Thanks for the video.

RobertCsala
Автор

that windows 7 bar sent me back in time

Gureenu
Автор

wow a big thanks for this vidéo, i was struggle a lot for retrieve a signal from an instanced object and this workflow made the trick !

albertpougnol
Автор

this is one of those videos that i should probably watch in a year. Godot still feels weird and new so cant really picture if this works best for what
(currently researching different methods for bullet collision)

inceant
Автор

This is great! I can tell this channel is going places!

ThinkWithGames
Автор

I use this pattern so much in my current project! is "message bus" a common name for the pattern or is it coined in this video? either way, I'm glad this video exists, because it really really cleans up my game's codebase. if I want to make a new UI element or something based on the general game state, it can be done super easily and completely decoupled from everything else.

anyways, great video! subscribed :D

auraspersonal
Автор

This is an great explanation. I thought signals were like radio broadcasts but I assume they are more like telephone wires connecting things.

alphabravo
Автор

From there, maybe implement an event-driven architecture. Add to the message bus 3 signals "emitter", "timestamp or flag" and "payload" and broadcast to every nodes, then each node is free to register to specific emitters or publish an event. I don't remember the name or where i saw this pattern.
For example a log node would store any events.

vincentvoillot
Автор

Thank you for this! I had no idea that I was already doing it back in the day in C# using static Actions as I have no idea about design patterns, but my main issue with that is there's no reliable way to disconnect an event.

But it looks fantastic in Godot, as I also found out that signals get auto-disconnected when freeing a Node! I can't wait to try this out properly on my game :)

johnjimenez
Автор

Finally, I found a second person who uses this pattern!

There are even more neat tricks you can do with this. For example, this is my menu overlay (the part that's there for every menu):

func _ready():
Bus.pause.connect(show)
Bus.unpause.connect(hide)

This is the AudioStream for the "bling!" when picking up stuff:

func _ready():


func _on_pickup(item, _player):
position = item.position
play()

Very minimal code, no component needs to know anything about any other. the item pickup signal has plenty more consumers, none of them knows anything about any other.

HenryLoenwind
Автор

Great video, perfect timing, just as I stated thinking about alert system in my stealth game)

del
Автор

Thanks for the video, really helpful and didatic!
In a note, perhaps the issue regarding a extense script with all events can be solved by breaking down each of the "Messeger" functionality in smaller batches
"PlayerMesseger" - "EnemyMesseger" etc

And then use the "Messeger" one to access those (just one auto-load).

brenocogu