Copy paste code from one project to another

Godot Version

`4.2.2

Question

i want to know why my code works in one script but not another ive double checked the nodes, input map , and animations but for some reason i cant jump or `play my animations when prompted by an input. just gives my null errors or just doesnt work or crashes.

heres the code in question


@onready var Sprite =$CanvasLayer/charctersprite/AnimatedSprite2D
@onready var Raycast = $RayCast3D
@onready var SpringArmPivot = $SpringArmPivot
@onready var Camera = $SpringArmPivot/Camera3D

const SPEED = 5.0
const JUMP_VELOCITY = 5.0
const MOUSE_SENS = 0.3 # Mouse sensitivity (you can tweak this)
const MINPIN = -80   # Minimum vertical rotation
const MAXPIN = 80    # Maximum vertical rotation

# Variables to store the current rotation angles
var yaw : float = 0
var pitch : float = 0 
var dead = false
# Get the gravity from the project settings to be synced with RigidBody nodes
var gravity = ProjectSettings.get_setting("physics/3d/default_gravity")


func _input(event):
	if dead:
		return
		
	if event is InputEventMouseMotion:
		yaw -= event.relative.x * MOUSE_SENS  # Horizontal rotation
		pitch -= event.relative.y * MOUSE_SENS  # Vertical rotation

# Clamp the pitch to prevent infinite rotation
		pitch = clamp(pitch, MINPIN, MAXPIN)

# Apply the rotation to the camera and the character's body
		SpringArmPivot.rotation_degrees.x = pitch  # Vertical rotation for the camera
		rotation_degrees.y = yaw  # Horizontal rotation for the character body

func _ready():
	Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)

func _unhandled_input(event):
	if Input.is_action_just_pressed("exit"):
		get_tree().quit()
	if Input.is_action_just_pressed("restart"):
		restart()

func _physics_process(delta):
	
	# Add the gravity.
	if not is_on_floor():
		velocity.y -= gravity * delta

	# Handle jump.
	if Input.is_action_just_pressed("jump") and is_on_floor():
		velocity.y = JUMP_VELOCITY

	# Get the input direction and handle the movement/deceleration.
	# As good practice, you should replace UI actions with custom gameplay actions.
	var input_dir = Input.get_vector("left", "right", "forward", "back")
	var direction = (transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
	if direction:
		velocity.x = direction.x * SPEED
		velocity.z = direction.z * SPEED
	else:
		velocity.x = 0.0
		velocity.z = 0.0

	if Input.is_action_pressed("click"):
		Sprite.play("punch")
	
	
	move_and_slide()

func restart():
	pass

what are the errors specifically? It sounds like the attached node does not have these same children as your other project.

so if i use the .play for anything it gives me an attempt to call function play n base null instance and game crashes

if i try to jump nothing happens

if i try to restart nothing happens

so far i can only move around. i double check all my nodes in the scene tree but ant find whats missing

hey i looked again over my nodes and i found the issue

i just assumed because they were named the same it would just pulg them in i didnt realized i needed to retype my onready’s to connect them to the nodes.

thanks for the help wouldnt have realized if you hadent said anything

It’s not that you have to re-type onready, I’m betting they had different paths.

These two lines are not the same because the first node is a great-grand-child and the second is only a child.

@onready var Sprite =$CanvasLayer/charctersprite/AnimatedSprite2D
@onready var Sprite =$AnimatedSprite2D
1 Like