I created a custom radial container for my game, and am using draw_texture()
to draw a texture at its center. Here is my script:
tool
extends Container
class_name RadialContainer
export(int) var radius = 100 setget set_radius
export(int, 0, 180) var separation = 30 setget set_separation
export(int, 359) var orientation = 0 setget set_orientation
var sprite_index: int
func set_radius(value: int):
radius = value
_draw()
func set_separation(value: int):
separation = value
_draw()
func set_orientation(value: int):
orientation = value
_draw()
func _draw():
draw_texture(load("res://assets/ui/dot.png"), Vector2(-3, -3))
var children = get_children()
var angle = (deg2rad(separation) / -2) * (children.size() - 1) - deg2rad(orientation)
for child in children:
child.rect_size = child.rect_min_size
child.rect_position = Vector2(radius, 0).rotated(angle) - (child.rect_size / 2)
angle += deg2rad(separation)
The problem is, the engine keeps throwing me errors about draw_texture()
every time one of these containers is drawn, despite draw_texture()
being inside a _draw()
function, and also despite the fact that the game seems to draw the texture just fine anyway.
E 0:01:29.546 draw_texture: Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal.
<C++ Error> Condition "!drawing" is true.
<C++ Source> scene/2d/canvas_item.cpp:812 @ draw_texture()
<Stack Trace> RadialMenu.gd:29 @ _draw()
RadialMenu.gd:15 @ set_radius()
Main.gd:98 @ load_location() # (This is where I'm adding the containers from)
Does anyone know what is happening here?