Skip to content

Custom drawing in 2D code update #8026

@yanourt

Description

@yanourt

Your Godot version:
Godot 4.1

Issue description:
The second code snippet does not work (export and setget):

extends Node2D

export (Texture) var texture setget _set_texture

func _set_texture(value):
    # If the texture variable is modified externally,
    # this callback is called.
    texture = value  # Texture was changed.
    queue_redraw()  # Trigger a redraw of the node.

func _draw():
    draw_texture(texture, Vector2())

instead this works fine for me:

extends Node2D

@export var texture : Texture :
	set(value):
		texture = value
		queue_redraw()
	get:
		return texture

func _draw():
	draw_texture(texture,Vector2())

URL to the documentation page:
https://docs.godotengine.org/en/latest/tutorials/2d/custom_drawing_in_2d.html

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions