I built a simple scene that I instanciate at will. Simply a KinematicBody2D as root, containing a Sprite and a CollisionShape2D. There is a script linked to the root node that basically expose a few properties to describe an orbit and make it move in orbit around its parent. The point being to make a very basic solar system simulation or anything that requires a node to move around another in a circular fashion.

Instanciated scene tree

The movement work fine and I’ve been playing around my scene tree, instancing a bunch and watching them move around as moons of planets, etc. But the texture is all the same. If I make children editable, I can go change the texture of the sprite, but I’d like to expose that property from the root node so I can access it directly from the editor.

I tried adding an exposed property with a setter and a getter to assign and retrieve the texture, but it seems to crash Godot completely with this code:

export(Texture) onready var texture setget texture_set, texture_get

func texture_set(newtexture):
    $"Sprite".texture = newtexture

func texture_get():
    return $"Sprite".texture

Is there a solution for that? Or simply another way?


I would export the texture variable from the root node and simply set the child texture in _ready(), rather than mess around with getters and setters.

export(Texture) var my_texture 

func _ready():
    get_node("Sprite").texture = my_texture
  • 1
    \$\begingroup\$ Always the simple solution that works ;) \$\endgroup\$ – BadgerBadger Apr 25 '18 at 22:15

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.