In the Pastebin link below is a big but well-commented script that functions as I want it to, but I have some questions. I am a newcomer to Godot, arriving from years of using Gamemaker. First, is it possible for this script to create the nodes it needs, instead of having to create them in Godot? (I think it is. I have tried, but to no avail. Is this behavior recommended?) Second, if the above is possible, how would I add a blank "width_curve" as well as a blank fill "gradient" to two of the three created nodes? (This is only for the draw lines.) Right now, the things described above are done in the Godot engine.

All nodes are Line2D, and there are three child nodes. The first child node is intended to have a "width" of zero (in the inspector). Its name should be "match_line". The next two child nodes both need to have an empty "width_curve" as well as an empty fill "gradient". Their names should be "draw_line_main" and "draw_line_match".

I would greatly appreciate the help. If possible, I will submit this to the asset library for anyone to use. I can tell that it is not ready for that currently. Feel free to use this script for whatever. It is offered as is. Use it at your own risk. It should draw a shaded vector shape.

EDIT: I have realized that the match_line node must be made in the editor, as it defines points that are best edited in the engine.

https://pastebin.com/5vYR0wS4

That's a lot of code and I'm not really sure what's wrong.

You can create new objects in code using the new keyword.

var n = Node2D.new()

You also don't need to create child nodes to save variables. Just have your main class inherit from Line2D, and then add those properties as member variables.

nothing is wrong with what it does. it works, but it needs a bit of optimization. Ive tried to create the nodes like this: 1) change line 41: FROM: onready var draw_line_main = get_node("draw_line_main") TO: onready var draw_line_main = Node2D.new()

2) change line 42: FROM: onready var draw_line_match = get_node("draw_line_match") TO: onready var draw_line_match = Node2D.new()

3) add the following code at line 87: add_child(draw_line_main) draw_line_main.set_owner(self)

add_child(draw_line_match)
draw_line_match.set_owner(self)

This does not work. I get an error that says "Invalid call. Nonexistant function 'add_point' in base Node2D" (points to what is line 101 in the pastebin text)

I was using Node2D as an example. You would use that with the correct class, like Line2D.

I changed Node2D to Line2D, but now it says "Attempt to call function 'set_offset' in base 'null instance' on a null instance." This point to what is line 147 in the pastebin link. the line is: draw_line_main.gradient.set_offset(0, 0)

Do I need to create the gradient somehow, or is the node being created incorrectly?

I'm actually not sure. I haven't used Line2D yet, just going by the documentation.

I've figured it out. The gradient does need to be created. (the width_curve stuff also needs to be created. Godot was pointing to the right place.) when something is written like this (when calling a function): name_of_a_node.any_text The "any_text" is a node, and it needs to be created too. ("name_of_a_node" is a variable.)

Things i was lacking: draw_line_main.gradient = Gradient.new() draw_line_main.width_curve = Curve.new() draw_line_match.gradient = Gradient.new() draw_line_match.width_curve = Curve.new()

Your code isn't formatted correctly :(

2 years later