Godot Version
4.2.2 stable
Question
I’m relatively new to Godot but have been quickly knocking out small projects. Without getting into too much detail, after doing some research I decided I wanted to take a stab at creating my own “Tile” node. The idea being this could potentially be used by itself or with a TileMap or upcoming TileMapLayer in 4.3 to get the functionality I want for the game idea I have.
I’m familiar with instantiating a child scene, but wanted to use @tool and class_name to get as close as possible to developing my own node, as I feel that’s a good skill to have. This is the code I have so far:
@tool
class_name Tile extends Area2D
var Sprite := Sprite2D.new()
var Hitbox := CollisionShape2D.new()
var Center := Marker2D.new()
@export var sprite_file: CompressedTexture2D:
set(texture):
Sprite.set_texture(texture)
notify_property_list_changed()
@export var collision_shape: RectangleShape2D:
set(shape):
Hitbox.set_shape(shape)
notify_property_list_changed()
func _ready():
add_child(Sprite)
add_child(Hitbox)
add_child(Center)
I can add a texture for the sprite and shape for the collision shape just fine but the Inspector doesn’t update with the selections. I searched and found notify_property_list_changed was suppose to be the solution but it isn’t working for me. Then I discovered that if I close the editor then reopen the project the texture and shape aren’t saved. I feel like these problems are related but after reading the documentation a ton and searching online I can’t figure it out. I’m going to go with instantiating a child scene since it’s a lot simpler and I am comfortable with that but I don’t want to just give up and not know what I was doing wrong.