Should I use custom signals or just emit_changed?

Godot Version

Godot 4.2

Question

I’ve created a project that has a “Character” resource, which my “Actor” node has and references. The “Actor” should change the sprite’s texture when the “Character” resource changes their current texture property. It also has an activate property that should be set to true when the character is talking, and off when it isn’t.

I’ve tried a few ways of doing this, and I’ve settled on the idea that the “Character” resource is the resource that is changing, but the “Actor” scene reflects these changes. Essentially the “Character” resource is piloting the “Character” mecha. This makes sense to me, as it allows me to access and change the character from an interactive story handler (Ink, for those wondering) without having to tell the “Actor” what to do inside of the story, and instead changing the character.

Here’s my question - Should I only use the “emit_changed” method when a property of the object changes, connecting to a generic “update” method that updates all the properties of Actor whenever the resource has a property that updates? Or should I have a separate signal for the current_texture and talking properties, each one connecting to a specific update method, like “update_current_texture” and “update_talking”?

Argument for just using emit_changed - Easier to program, only have one update method that I can edit if there’s anything else I want to add.

Argument for specific functions - Seems less wasteful, especially if I’m making multiple changes per frame.

Is anyone aware of any issues I may come across if I don’t use the emit_changed method?

Thanks!

No, the approach sounds fine. If you need to monitor multiple things on the object it would be a judgement call to use one signal with a parameter and a matcher to forward to the right method, or an independent signal for each. I would not use the changed signal if you then need to figure out what changed…if you don’t care what changed then yes it’s good enough. I think It would be smarter to use custom signals if you do care.

I would go for individual signals.

  • the autogenerated connection function (_on_actor_signalname) on the receiver is very easy to read and understand where signal is origined; in the advent they get disconnected when reorganizing a scene or moving the node/script elsewhere.
  • stack traces and debugging are easier to read.

I would say you could use changed just fine.

The Actor would know what things to take from the Character. Something like:

func character_changed():
  # check that character.texture is legit
  if character.texture:
    self.texture = character.texture
  # etc. for all the stuff you want to pull out of character

Custom signals are fine, but then you also end-up with a lot of connects and handlers. It’s up to you.