Packed scene is somehow loading the incorrect scene?

Godot Version

Godot Version 4.3

Question

Whenever I drag the scene from the filesystem into the node tree, it loads the correct scene. However, when I start the game, for whatever reason it’s loading the incorrect scene? I have a video attached. I have no idea what’s happening.

Can you share some of your code? like weaponhandler and knife/pistol?

weaponhandler.gd

extends Node3D

@export var currentWeapon = preload("res://weapons/pistol.tscn")
var weapon : Node3D

var inventory : Array = []

func _ready():
	inventory = get_children()

func changeWeapon(num):
	if weapon:
		weapon.visible = false
		weapon.equipped = false
	inventory = get_children()
	weapon = inventory[num % inventory.size()]
	
	weapon.equipped = true
	weapon.visible = true

weapon.gd

extends Node3D

@export var ammo = 12
@export var reserve = 36
@export var magazine_size = 12

@export var damage = 35

@export var reloadSpeed : float = 2.0
@export var fireCooldown : float = 0.2

@export var fireRange = 300.0

@export var fireSound : AudioStreamPlayer
@export var reloadSound : AudioStreamPlayer

@onready var camera : Camera3D = get_viewport().get_camera_3d()

var reloading = false
var canFire = true

@export var equipped = false

func _input(event):
	if !equipped:
		return
	if event.is_action_pressed("attack"):
		if !reloading and (ammo > 0 or magazine_size == 0) and canFire:
			ammo = max(ammo-1,0)
			fireSound.play()
			canFire = false
			
			var from = camera.global_position
			var to = camera.global_position - camera.global_transform.basis.z * fireRange
			#print(from)
			#print(to)
			var query = PhysicsRayQueryParameters3D.create(from,to)
			query.collide_with_areas = true
			#query.collision_mask = 0b10100000
			
			var result = get_world_3d().direct_space_state.intersect_ray(query)
			#print(result)
			if result:
				var hit : Node3D = result.collider
				if hit.has_meta("EnemyType"):
					hit.health -= damage
			
			await get_tree().create_timer(fireCooldown).timeout
			canFire = true
			
	elif event.is_action_pressed("reload"):
		if ammo < magazine_size and reserve > 0:
			reloadSound.play()
			reloading = true
			await get_tree().create_timer(reloadSpeed).timeout
			if reserve > magazine_size - ammo:
				reserve -= magazine_size - ammo
				ammo = magazine_size
			else:
				ammo += reserve
				reserve = 0
			reloading = false

I’ve since fixed it; I needed to save each scene as a new scene and simply deleted the buggy one. I have absolutely no idea why it was bugging out so badly.

1 Like

I’m running 4.3 here, and I have occasionally had Godot do screwy things because its cache got out of sync. It sounds a lot like what you saw. For me, the fix is usually to nuke the .godot directory, though I don’t advise doing that without making sure your project is backed up.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.