Script no longer working after two scene transitions
Asked Answered
V

4

0

Hi there, completely new to godot, taking my first babysteps. I've done development in unity before and have to unlearn a few things. Recreated the tutorial game squash the creeps so I'm not totally clueless
Just made a simple little test of a 3d plane with a player square, a house, a way to enter, a second scene with the house interior and a way to exit.
I load up the main scene (my "outside") and preload the inside of the house
I can enter the house by being inside an area3d in front of it (i switch a bool upon entering the are) and hitting enter
Once inside i can exit via the same system
But once I'm outside again, my camera tracking does no longer work and my "enter" events are not heard any longer. I'm not sure whats going on here, is the main script not loaded? what could be the cause of this? Am I missing a checkmark somewhere?

Probably a very easy beginner mistake, But I'm so new to the menus..

My code for the main scene:

extends Node3D
var houseinside = preload("res://Insidehouse.tscn").instantiate()
var someoneAtTheDoor = false

# Called when the node enters the scene tree for the first time.
func _ready():
	pass # Replace with function body.


# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
	$CameraPivot.look_at($Player.position)


func _unhandled_input(event):
	if event.is_action_pressed("ui_accept") and someoneAtTheDoor:
		# This restarts the current scene.
		enterHouse()

func enterHouse():
	print_debug("Entering House")
	get_tree().root.add_child(houseinside)
	someoneAtTheDoor = false
	queue_free()


func _on_house_someone_at_the_door():
	someoneAtTheDoor = true


func _on_house_someone_left_the_door():
	someoneAtTheDoor = false

code for the house object:

extends StaticBody3D
signal someoneAtTheDoor
signal someoneLeftTheDoor

# Called when the node enters the scene tree for the first time.
func _ready():
	pass # Replace with function body.


# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
	pass


func someoneIsAtTheDoor():
	someoneAtTheDoor.emit()
	$EnterText.visible = true

func _on_door_area_body_entered(body):
	someoneIsAtTheDoor()
	print_debug("entered")

func _on_door_area_body_exited(body):
	print_debug("left")
	someoneLeftTheDoor.emit()
	$EnterText.visible = false

and for the inside of the house:

extends Node3D
var outside = preload("res://main.tscn").instantiate()
var someoneAtTheDoor = false

# Called when the node enters the scene tree for the first time.
func _ready():
	pass # Replace with function body.


# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
	pass


func _unhandled_input(event):
	if event.is_action_pressed("ui_accept") and someoneAtTheDoor:
		# This restarts the current scene.
		enterHouse()

func enterHouse():
	# This is like autoloading the scene, only
	# it happens after already loading the main scene.
	get_tree().root.add_child(outside)
	someoneAtTheDoor = false
	queue_free()

func _on_door_area_body_entered(body):
	someoneAtTheDoor = true
	print_debug("entered")
	$LeaveText.visible = true

func _on_door_area_body_exited(body):
	someoneAtTheDoor = false
	print_debug("left")
	$LeaveText.visible = false

edit: also, if there is a better way for screne transition, I'd be happy to hear it!

Vadose answered 23/11, 2023 at 16:28 Comment(0)
H
0

Do you have errors in the debugger?

Happenstance answered 23/11, 2023 at 17:25 Comment(0)
V
0

Happenstance

Nope, no errors.

Vadose answered 23/11, 2023 at 18:12 Comment(0)
G
0

How are these events being connected to your signals? It looks to me like you're probably manually assigning them. If that is the case, go inside then back outside and see if they're still connected. In the scene view, click on the "remote" tab. That lets you see the current states of your objects. Then click on your nodes and look to see if their signals are still assigned in the inspector, or if anything else looks strange.

Godwin answered 23/11, 2023 at 18:50 Comment(0)
V
0

Godwin

Well the simplest thing that makes me think the script ist loaded properly is the camera movement.
I do that with a simple lookat in the _process function.
just put a print_debug in the _process, keeps on continually firing. Then, once i exit the building... nothing. No more debug messages.

oh well, just changed my system to get_tree().change_scene_to_file and that works fine. Seems like i was referencing something that was decoupled from their script or something

Case closed for now, thanks!

Vadose answered 23/11, 2023 at 22:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.