Invisible 2D Objects in Godot - Can Click But Not See Them

Godot Version

4

Question

Hello everyone,

I’m working on a 2D incremental game in Godot 4, and I’m facing an issue where my spawned objects are functionally present (I can click on them and they work) but they’re completely invisible. The objects spawn correctly, I can interact with them, but I cannot see their sprites.

Here’s my setup:

Game Structure:

Main scene with GameManager, Cursor, Slime, and UI nodes

ClickableObject scene that gets instantiated by GameManager

The Problem:

Objects spawn at correct positions (confirmed via print statements)

Click detection works fine - I get mass when clicking where objects should be

No sprite visibility, even with fallback textures

No errors in console related to sprites or textures

What I’ve Tried:

Ensured Sprite2D nodes exist in ClickableObject scene

Added fallback colored circles when textures don’t load

Verified z-index settings

Checked global_position vs position

Confirmed textures exist in the correct paths

Relevant Code Snippets:

GameManager spawn function:

func spawn_object():
if object_scene == null:
return

var new_object = object_scene.instantiate()
get_parent().add_child(new_object)
new_object.add_to_group("clickable_objects")

var object_type = get_object_type_for_stage(current_stage)
var mass_value = get_mass_value_for_type(object_type)
mass_value *= object_value_multiplier

var viewport = get_viewport()
var screen_size = viewport.get_visible_rect().size
var margin = 50

var pos_x = randf_range(margin, screen_size.x - margin)
var pos_y = randf_range(margin, screen_size.y - margin)
new_object.position = Vector2(pos_x, pos_y)

if new_object.has_method("setup"):
    new_object.setup(object_type, mass_value)

print("Spawned ", object_type, " at: ", new_object.position)

ClickableObject setup:

func setup(type: String, value: float):
object_type = type
mass_value = value

var sprite = $Sprite2D
if sprite == null:
    print("ERROR: No Sprite2D node found!")
    return

# Try to load texture
if sprite_paths.has(type):
    var texture_path = sprite_paths[type]
    var texture = load(texture_path)
    if texture:
        sprite.texture = texture
        sprite.modulate = Color.WHITE
    else:
        use_fallback_color(sprite, type)
else:
    use_fallback_color(sprite, type)

The objects ARE there (clickable), but completely invisible. What could be causing sprites to not render in a 2D Godot project?

and there another one problem

Cursor sprite doesn’t follow the mouse - I have a cursor Area2D with a circle sprite that should follow mouse movement

Objects don’t break within cursor circle radius - Objects should be destroyed when they’re within the cursor’s radius circle

Here’s my current cursor implementation:

Cursor.gd:

gdscript
extends Area2D

@onready var collision_shape = $CollisionShape2D
var circle_sprite

func _ready():
# Create visual circle for radius
circle_sprite = Sprite2D.new()
var circle_texture = load(“res://assets/sprites/Cursor.png”)
if circle_texture:
circle_sprite.texture = circle_texture
else:
# Create simple circle programmatically
var image = Image.create(64, 64, false, Image.FORMAT_RGBA8)
image.fill(Color(1, 1, 1, 0.3))
circle_sprite.texture = ImageTexture.create_from_image(image)

circle_sprite.modulate = Color(1, 1, 1, 0.3)
add_child(circle_sprite)
update_circle_radius(100.0)

func update_circle_radius(radius: float):
if collision_shape and collision_shape.shape is CircleShape2D:
collision_shape.shape.radius = radius
if circle_sprite:
circle_sprite.scale = Vector2(radius / 32.0, radius / 32.0)
GameManager.gd (relevant parts):

gdscript
func try_auto_click():
if auto_click_damage > 0:
var objects = get_tree().get_nodes_in_group(“clickable_objects”)
for obj in objects:
if cursor and obj.global_position.distance_to(cursor.global_position) <= cursor_radius:
on_object_damaged(obj, auto_click_damage)

func on_object_hovered(object, base_damage: float):
var damage = base_damage * mass_multiplier * click_multiplier
var is_critical = randf() < critical_chance

if is_critical:
    damage *= critical_multiplier
    spawn_critical_text(object.position, damage)

on_object_damaged(object, damage)

The issues:

The cursor Area2D doesn’t follow mouse movement

Objects don’t get destroyed when within the cursor radius

The circle sprite shows the radius but doesn’t move with the cursor

What I’ve tried:

Using get_global_mouse_position() but not sure where to implement it

Verified collision shapes and groups are set up correctly

Checked that objects are in the “clickable_objects” group

Any help would be greatly appreciated!

Post your object scene structure with sprite node selected and sprite properties visible in the inspector. Post your remote scene tree.

Are sprites visible if you comment out all your sprite/texture assignment code and just assign the default godot icon manually to the sprite in the inspector?

Okay, now post a screenshot. I can say that right now I’ve given a texture to the sprite and the objects are no longer invisible, but they’re with the texture I’ve set for them.

Check if setup() ever gets called by putting a print statement or a breakpoint into it.

It doesn’t look like it gets called because you check if the top node of the instantiated scene has the setup() method, and call it only if that’s true. Since the script is not attached to the top node in the scene, this check will return false, setup() won’t be called and no sprite texture will be assigned.

Always print everything every step of the way, to see where your code is going and what it’s doing to variable values.

1 Like

Yeee its work thank u!

It works, but can you please help with the circle that should follow the cursor, but it doesn’t follow the cursor for some reason

Where do you set circle’s position?

I put it in the center, but it seems to me that it should immediately move to the cursor.

just I want to make a game like a game.
A Game About Feeding A Black Hole

and it have this circle

Why would it move if you didn’t instruct it to move?

no i have script but it dont work

extends Area2D

@onready var collision_shape = $CollisionShape2D
var circle_sprite

func _ready():
# visual
circle_sprite = Sprite2D.new()
var circle_texture = load(“res://assets/sprites/Cursor.png”)
if circle_texture:
circle_sprite.texture = circle_texture
else:

	var image = Image.create(64, 64, false, Image.FORMAT_RGBA8)
	image.fill(Color(1, 1, 1, 0.3))
	circle_sprite.texture = ImageTexture.create_from_image(image)

circle_sprite.modulate = Color(1, 1, 1, 0.3)
add_child(circle_sprite)
update_circle_radius(100.0)

func _process(_delta):
# move to curs.
global_position = get_global_mouse_position()

func update_circle_radius(radius: float):
if collision_shape and collision_shape.shape is CircleShape2D:
collision_shape.shape.radius = radius
if circle_sprite:
circle_sprite.scale = Vector2(radius / 32.0, radius / 32.0)

To properly format the code:

```
[paste code here]
```

okay here

How is this related to circle.gd you previously posted?

these are the same scripts

They don’t look same to me. I don’t see _process() function in the one from your first post.

In any case. Put print statement in the _process() where you set the position and print out that position.

lol the script is dont work

print dont works

Make sure that the script is actually attached to the node.

1 Like

it work but why there 2 circles

oh i fix this. Tysm for help!