#Best way to plug a node into an export variable?

21 messages · Page 1 of 1 (latest)

livid magnet
#

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.)

fresh dagger
#

You can do that with Resources

livid magnet
#

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...

steel briar
#

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).

livid magnet
#

How will I resize it?

steel briar
livid magnet
#

I see

steel briar
#

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)```
livid magnet
#

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

livid magnet
#

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?

steel briar