I have 2 custom types of nodes, living and hurtbox.
Living nodes will almost always need a hurtbox (as well as a hitbox and collision shape)
It's annoying to have to search up nodes I know I'm going to need, via 'add child node' every time I make a new Living.
I can't just make it a scene or spawn a hurtbox via code, because I need to edit the hurtbox's position.
Is there some shortcut to spawn a node that I know I'm going to need?
(As seen in the third image, collision shape 2d lets you create a new shape, although that's probably just be an enum or something.)
#Best way to plug a node into an export variable?
21 messages · Page 1 of 1 (latest)
You can do that with Resources
I see. So there's no way to do it with a node?
Alternatively, is there any way to make my hurtbox node type into a resource?
I'm not sure resources can be resized in the 2d editor...
Yes, you can convert your Hurtbox (or any custom node) into a Resource in Godot by creating a custom resource class.
Instead of extending Area2D for Hurtbox, extend Resource. This will allow you to save data and reference the Hurtbox as a reusable resource.
Once its a resource, it won’t function as a node, but it can store data to be applied to a Node (e.g., to an Area2D that handles the hurtbox functionality).
How will I resize it?
In the inspector only, cant do it in 2d editor
I see
If all you need is to add child nodes quickly, maybe scene inheritance
You can use scene inheritance to create a base scene for your Living nodes that already includes the Hurtbox, Hitbox, and CollisionShape2D. This way, every time you create a new Living node, it will already have those child nodes in place, and you can modify them directly in the editor.
You can do that manually or create a script to automatically apply them whenever a living node is created
something like this
class_name Living
func _init():
# Create Hurtbox
var hurtbox = Hurtbox.new()
add_child(hurtbox)
# Create Hitbox
var hitbox = Area2D.new()
add_child(hitbox)
# Create CollisionShape2D
var collision_shape = CollisionShape2D.new()
hitbox.add_child(collision_shape)```
I thought about scene inheritance, but no such thing existed, as far as I could tell
All of the discussions about scene inheritance were describing making a scene a child node
Also, _init() doesn't run in-editor, does it? I wouldn't be able to resize these child nodes even with inspector, right?
Either way, I've realized that using ECS instead of inheritance would magically solve all of my problems.
If I marked this as solved, will it lock the thread?
No it wont.