0 votes

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?

Godot version 3.5.1.stable
in Engine by (20 points)

1 Answer

0 votes
Best answer

Don't call _draw manually in the setters. Ideally, you mean to call update() instead. The engine will call _draw.

https://docs.godotengine.org/en/stable/tutorials/2d/custom_drawing_in_2d.html

by (834 points)
selected by
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.