CollisionShape2D Node not appearing in scene, despite Godot recognising its position and extents

Godot Version

Godot-4

Question

Having an issue with a collisionshape2d that I’ve generated using a script attached to its parent, area2d node. The code is below, and as you can see I’ve generated the extents of the shape by referencing the h/w of a sprite node’s texture. As you can see from the SC of the debug messages, Godot recognises both the position and dimensions of the collisionshape2d node. However, despite having the visibility turned on, with a clear debug colour, and even when making the sprite2d invisible, the collision shape does not appear when i run the scene. To test further I have also ran a character with collision detection through it in another scene and there is nothing detected by Godot. Could anyone suggest where I’ve gone wrong?

extends Area2D

class_name PowerUp

@export var texture: Texture2D

func _ready():
$PowerUpSprite.texture = texture
set_collision_shape_size()

func set_collision_shape_size():

var size = Vector2($PowerUpSprite.texture.get_width(), $PowerUpSprite.texture.get_height())

$PowerUpBox.shape.extents = size / 2

$PowerUpBox.position = Vector2.ZERO

print ("collision shape set to", $PowerUpBox.shape.extents, ".")

print ("collision shape is at", $PowerUpBox.position, ".")

Do you have visible collisionshapes turned on in the debug-tab? You can also check the remote-scenetree to double check that the collisionshape exists

Ahhh thank you so much! That was it- bit silly of me not to check that!

1 Like