[Plugins] How to define custom node type with child nodes?

Godot Version

Godot 4.2

Question

I’m working on a plugin

This plugin adds some custom nodes that I’m developing.

For the sake of simplicity let’s just assume that one of the custom nodes is a variation of Area2D

This new node is called AreaCount2D. Works exactly the same as Area2D but:

  • Internally it stores references to bodies/areas
  • Will only emit the typical Area2D signals when bodies/areas enter/exit the Area2D a certain amount of times (defined by user)

So basically, this new AreaCount2D is the same as Area2D but adds a new public field (the count required) and some internal (not exposed) behaviour

My plan to implement this is to create a node inheriting from Collision2D (the same parent that Area2D has) then adding a child Area2D to this node, so basically I will connect all the signals emitted on the regular Area2D to the root of this new custom AreaCount2D node. Then on the called functions add the functionality stated above.

AreaCount2D (This inherits from Collision2D)
├ Area2D
└ Other nodes i might need to implement AreaCount2D?

However, I’m not sure how to implement this… in the docs its stated that I need to implement a couple tool scripts, one for registering new node types and another for the custom type… but where can I add the child Area2D that my new AreaCount2D has?

Correct. That’s the plugin’s script.

Correct. That’s the script for the custom node you’re adding.

In the script for the custom node you’re adding – must be via code!