Child scenes scripts not running

Godot Version

4.2

Question

Hello. I’m new to Godot and have encountered a problem: When i run a scene, if any child scenes have scripts attached to them, for some reason, they don’t run. In my case, the player’s animations and movements don’t work on a level scene. Here’s my code for the player:



const SPEED = 10.0
const JUMP_VELOCITY = -13.0 ## These 2 numbers are basically random

var gravity = ProjectSettings.get_setting("physics/2d/default_gravity")

@onready var _animated_sprite = $AnimatedSprite2D	

func _ready():
	pass
func _physics_process(delta):
	if not is_on_floor():
		velocity.y += gravity * delta

	if Input.is_action_just_pressed("ui_accept") and is_on_floor():
		velocity.y = JUMP_VELOCITY

	if Input.is_action_pressed("ui_left"):
		velocity.x = SPEED
		_animated_sprite.play("run")
		_animated_sprite.flip_h = true
	elif Input.is_action_pressed("ui_right"):
		velocity.x = - SPEED
		_animated_sprite.flip_h = false
		_animated_sprite.play("run")
	
	if Input.is_anything_pressed() == false:
		_animated_sprite.play("idle")

	move_and_slide()

Could you send a screenshot of your level scene tree?

How sure are you that the script isn’t running and it’s not just doing nothing for a different reason? For example, have you tried putting a print statement at the top of _physics_process?

Scripts should run so I don’t know what the issue is. Check that the player scene is able to process in the level scene. If you select the player node and go to the inspector, under the Node properties at the bottom there’s a selection for when the node processes. This is “Inherit” by default, which means the _process and _physics_process methods run if the parent node is set up to run too. If that’s been changed to be disabled or the larent isnt processing, that could be it. Most likely it’s something unexpected in your script.

image

here’s my scene tree.
Also yes, i tried putting a print in basically all of the functions. If i launch the player scene on its own, everything works, but if i launch the Node2D its script works, but the player script doesn’t. I also tried reinstalling Godot, but that did nothing

Somehow deleting my character node and adding it back fixed everything. Thanks for help tho!

It’s because the player in the level had no script attached. See how there was no icon for the script but now there will be?

1 Like